Thread: Avoiding Global variables

  1. #31
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by csonx_p View Post
    Ok, took me a while but managed to convert all the code to pure C... I now can compile but down to two warnings... This has to do with the ID of the child window

    Code:
    HWND CreateButton(const HWND hParent,const HINSTANCE hInst,DWORD dwStyle,
    				  const RECT& rc,const int id,const ustring& caption)
    {
    	dwStyle|=WS_CHILD|WS_VISIBLE;
    	return CreateWindowEx(0,         
    		_T("button"),               
    		caption.c_str(),            
    		dwStyle,                    
    		rc.left,                     
    		rc.top,                      
    		rc.right,                     
    		rc.bottom,                    
    		hParent,                      
    		reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
    		hInst,                        
    		0);                        
    }
    What you see above is a C++ style, converting into C ...

    Code:
    (HMENU)id
    ... gives a warning

    Code:
    warning C4312: 'type cast' : conversion from 'int' to 'HMENU' of greater size
    Ignoring this warning disables the minimize/restore/close buttons on the window... Any ideas on how to convert this properly?
    Got read of the warnings by casting the arguments and declaring id as 'HMENU' not 'const int' in the parameter list... But, still have the close/minimize button missing! Could there be anything i removed by mistake... Please assist!

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, that's weird, because those have to do with the window style.
    You'll have to make sure the window style is correct...
    I believe you need the WS_SYSMENU style to see the max/min buttons.

    And as you know, reinterpret_cast and static_cast are C++ only, so you have to do a C-style cast to make it C.
    But what's weird is that I never get the warning you do by casting int to HMENU, even with a C-style cast.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    I believe you need the WS_SYSMENU style to see the max/min buttons.
    Currently dStyle is 0, when i change to WS_SYSMENU the application runs minimized (doesn't even show)...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-06-2008, 09:59 AM
  2. global variables
    By shadovv in forum C++ Programming
    Replies: 7
    Last Post: 10-24-2005, 02:21 PM
  3. global variables - okay sometimes...?
    By MadHatter in forum C++ Programming
    Replies: 21
    Last Post: 01-21-2003, 04:23 PM
  4. global variables
    By rdnjr in forum Linux Programming
    Replies: 0
    Last Post: 01-07-2003, 10:28 AM
  5. Global variables? Bad! Yes, but to what extent?
    By Boksha in forum C++ Programming
    Replies: 6
    Last Post: 05-26-2002, 04:37 PM