Skip to main content
gamedev.net
🔒 Locked

CreateWindowEx

Started by Mattman Oct 29, 2002 at 4:48 AM 3 replies 1.2k views
Original Post
Mattman
Mattman
I have the following lines of code in my program:
    WNDCLASSEX window;
    HWND hWnd;
    MSG msg;
	    
    window.cbSize = sizeof(WNDCLASSEX);
    window.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    window.lpfnWndProc = WinProc;
    window.cbClsExtra = 0;
    window.cbWndExtra = 0;
    window.hInstance = hInstance;
    window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    window.hCursor = LoadCursor(NULL, IDC_ARROW);
    window.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
    window.lpszMenuName = NULL;
    window.lpszClassName = "TheGame";
    window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    // register the window class
    if (!RegisterClassEx(&window))
        return (0);

    MessageBox(NULL, "DEBUG 1", "DEBUG", NULL);
    // create the window
    if (!(hWnd = CreateWindowEx(NULL,
                                "TheGame",
                                "Sample",
                                WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE,
                                0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                                NULL,
                                NULL,
                                hInstance,
                                NULL)))
    {
        return (0);
    }
    MessageBox(NULL, "DEBUG 2", "DEBUG", NULL);
 
This code used to work flawlessly. Suddenly, it decided to not work no matter how many times I reboot, or no matter how many times I change the registering class name. The problem lies in the CreateWindowEx line (I know this because the first MessageBox displays, but the second one doesn't). Does anyone know why it's suddenly screwed up, and how I might go about fixing it? Thanks SO MUCH...this is obviously a major setback, as it stops my entire program from running! [edited by - Mattman on October 29, 2002 1:36:35 PM]
Andrzej Wasylkowski
Andrzej Wasylkowski
The problem may be not in CreateWindowEx function, but in WM_CREATE message handler. The handler is executed right after call to CreateWindowEx and that may be the reason why the second message box doesn''t show up. Just take a look at your WndProc and WM_CREATE message handler and see if everything is OK.

Hope that helps.

Mattman
Mattman
I just have return(0) for WM_CREATE, which is exactly what I had before.
Darrell L
Darrell L
The WS_EX_TOPMOST style needs to be in the dwExStyle parm location (where you have the first NULL), not with the other dwStyle parm settings.

For future efforts, when CreateWindowEx returns a NULL handle, or you get an error condition from any API call, you might want to try putting in a call to FormatMessage, using a GetLastError call as the messageid parm. Then you can messagebox the error message (or log it to your game log file) to tell you what may be causing the problem and at least give you some sort of starting point for debugging your code. Or at the very least, when you exit your app due to an error condition, return the value of GetLastError so you can at least look up what the problem via the return code value.

It''s also a good practice to first just comment out code that you''re changing, instead of replacing it entirely. That way you can refer back to it or uncomment it and comment out the new code, so at least you can continue on with your work. Sort of a mini-version control.
Mattman
Mattman
By using FormatString() and passing the DWORD returned by GetLastError() , the error in my MessageBox says "Cannot create a file when that file already exists. " What does this mean? Again, the error occurs when trying to call CreateWindowEx() . Thanks for the help!

[edited by - Mattman on October 29, 2002 1:47:59 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.