WIN32 Help

This is a discussion on WIN32 Help within the Windows Programming forums, part of the Platform Specific Boards category; I try to compile the following code and it has an error with this part Code: if (!(hwnd = CreateWindowEx(NULL, ...

  1. #1
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77

    WIN32 Help

    I try to compile the following code and it has an error with this part





    Code:
    if (!(hwnd = CreateWindowEx(NULL, // extended style
                                WINDOW_CLASS_NAME,   // class
    						    "Your Basic Window", // title
    						    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    					 	    0,0,	    // initial x,y
    						    400,400,  // initial width, height
    						    NULL,	    // handle to parent 
    						    NULL,	    // handle to menu
    						    hinstance,// instance of this application
    						    NULL)))	// extra creation parms ****THIS IS WERE THE ERROR IS****

    it says
    Code:
    warning: trying to convert NULL to a non-ponter type.
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You should be able to ignore that *warning*. Check to see if your program compiled...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    nope didn't compile
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  4. #4
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    BUMP



    If you need me to I"ll post the full code.




    ~Trooper
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You are using CreateWindowEX() which allows extended windows styles then you don't specify an extended style. Use CreateWindow() or

    Try

    CreateWindowEx( WS_EX_APPWINDOW,
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    okay I tried that now i get this error


    Code:
    function `int WinMain(HINSTANCE__ *, HINSTANCE__ *, CHAR *, int)':
     `WINDOW_CLASS_NAME' undeclared (first use this function)
     (Each undeclared identifier is reported only once
     for each function it appears in.)
     type `const WNDCLASSA' is not a base type for type `WNDCLASSEX'
     warning: converting NULL to non-pointer type
    here is the full code if your bored...

    Code:
    // Define //////////////////////////////////////////////////////////////////////
    #define WIN32_LEAN_AND_MEAN //no MFC
    #define WINDOWS_CLASS_NAME "WINCLASS1"
    
    
    // Include Files///////////////////////////////////////////////////////////////
    #include <windows.h>  //The main Window
    #include <windowsx.h> //Macros
    #include <stdio.h>
    #include <math.h>
    
    // Global Varables ////////////////////////////////////////////////////////////
    
    // Main Window ////////////////////////////////////////////////////////////////
    LRESULT CALLBACK WindowProc(HWND hwnd, 
    						    UINT msg, 
                                WPARAM wparam, 
                                LPARAM lparam)
    {
    // this is the main message handler of the system
    PAINTSTRUCT	ps;	// used in WM_PAINT
    HDC	hdc;	// handle to a device context
    
    // what is the message 
    switch(msg)
    	{	
    	case WM_CREATE: 
            {
    		// do initialization stuff here
    
            // return success
    		return(0);
    		} break;
    
    	case WM_PAINT: 
    		{
    		// simply validate the window
    		hdc = BeginPaint(hwnd,&ps);	 
    		// you would do all your painting here
            EndPaint(hwnd,&ps);
    
            // return success
    		return(0);
       		} break;
    
    	case WM_DESTROY: 
    		{
    		// kill the application, this sends a WM_QUIT message 
    		PostQuitMessage(0);
    
            // return success
    		return(0);
    		} break;
    
    	default:break;
    
        } // end switch
    
    // process any messages that we didn't take care of 
    return (DefWindowProc(hwnd, msg, wparam, lparam));
    
    } // end WinProc
    
    // WINMAIN ////////////////////////////////////////////////
    int WINAPI WinMain(	HINSTANCE hinstance,
    					HINSTANCE hprevinstance,
    					LPSTR lpcmdline,
    					int ncmdshow)
    {
    
    WNDCLASSEX winclass; // this will hold the class we create
    HWND	   hwnd;	 // generic window handle
    MSG		   msg;		 // generic message
    
    // first fill in the window class stucture
    winclass.cbSize         = sizeof(WNDCLASSEX);
    winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                              CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc	= WindowProc;
    winclass.cbClsExtra		= 0;
    winclass.cbWndExtra		= 0;
    winclass.hInstance		= hinstance;
    winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
    winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
    winclass.lpszMenuName	= NULL;
    winclass.lpszClassName	= WINDOW_CLASS_NAME;
    winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
    
    // register the window class
    if (!RegisterClass(&winclass))
    	return(0);
    
    // create the window
    if (!(hwnd = CreateWindowEx(NULL, // extended style
                                WINDOW_CLASS_NAME,   // class
    						    "Your Basic Window", // title
    						    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    					 	    0,0,	    // initial x,y
    						    400,400,  // initial width, height
    						    NULL,	    // handle to parent 
    						    NULL,	    // handle to menu
    						    hinstance,// instance of this application
    						    NULL)))	// extra creation parms
    return(0);
    
    // enter main event loop
    while(GetMessage(&msg,NULL,0,0))
     	 { 
    	 // translate any accelerator keys
    	 TranslateMessage(&msg);
    
    	 // send the message to the window proc
    	 DispatchMessage(&msg);
    	 } // end while
    
    // return to Windows like this
    return(msg.wParam);
    
    } // end WinMain


    ~Trooper
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Just use your original code. However, CreateWindowEx takes a DWORD as its first argument and not a pointer so use 0 instead of NULL.
    Code:
    if (!(hwnd = CreateWindowEx(NULL, // wrong!
    if (!(hwnd = CreateWindowEx(0,       // right!
    Also use RegisterClassEx in place of RegisterClass.

    EDIT: Change the define from WINDOWS_CLASS_NAME to WINDOW_CLASS_NAME so that it matches your other code.
    Last edited by anonytmouse; 09-29-2003 at 09:56 PM.

  8. #8
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    Wow, Thanks a lot. 1 more thing I get this error



    Code:
     undefined reference to `GetStockObject@4'

    weird error huh.



    ~Trooper


    Thanks a lot.
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  9. #9
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    This is a linker error that means the function can not be found. If you look at the bottom of the GetStoickObject doc page you find:
    Library: Use Gdi32.lib.
    So try linking with gdi32.lib.

  10. #10
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    umm how would I go about doing that in Dev-C++?



    ~Trooper
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  11. #11
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    BUMP



    Please help me I can't get this figured out.



    ~Trooper
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

  12. #12
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Project -> Project Options -> Parameters Tab

    Under Linker,

    add this line
    -lgdi32

  13. #13
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Also make sure you're compiling a GUI project on Dev-C++:

    Project -> Project Options

    On the General tab, make sure the type is WIN32 GUI.

  14. #14
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    Yeehaw!!! Thanks sooooooo much.



    ~Trooper
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console program to Win32
    By Ducky in forum Windows Programming
    Replies: 3
    Last Post: 02-25-2008, 12:46 PM
  2. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 04:26 PM
  3. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 06:57 PM
  4. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 10:09 AM
  5. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 04:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21