Hwnd is null?

Started by
7 comments, last by Xai 17 years, 11 months ago
Hello everyone, I was sitting here trying to recreate pong with OpenGL and Windows, but my application is not working, because when I set Hwnd to create a window, it doesn't work and comes up null. Here take a look at my winmain.

int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;        
    MSG msg;
    BOOL bQuit = FALSE;
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "PongAPP";
    RegisterClass (&wc);

    hWnd = CreateWindow (
      "Pong", "PongAPP",
      WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
      0, 0, 800, 800,
      NULL, NULL, hInstance, NULL);
    if(hWnd == NULL)
    {
        MessageBox(NULL, "HWND is null", "WinMain", MB_ICONEXCLAMATION);
        return 0;
    }

    EnableOpenGL (hWnd, &hDC, &hRC);
    gameInit();

    while (!bQuit)
    {
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
            gameRun(hDC);
        }
    }
    DisableOpenGL (hWnd, hDC, hRC);

    DestroyWindow (hWnd);

    return msg.wParam;
}

Can someone help me out here?
Advertisement
maybe your resolution is 800x600 and you are trying to set 800x800
It looks like something is going wrong in your window creation call. Try using GetLastError() to see if you can get a more specific error.

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Quote:Original post by freenity
maybe your resolution is 800x600 and you are trying to set 800x800


His window is going to end up 800 x 800, he's not trying to change resolution. Just thought I would clear that up while I was here. [smile]

-AJ
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
How exactly do I use getLastError? I ran the function but it didn't do anything so I tried to save what it returns into a variable which didn't work, I'm not sure how to use the function exactly.
Allow me to introduce MSDN
[s]--------------------------------------------------------[/s]chromecode.com - software with source code
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE

make sure one of these is not mutually-exclusive with another. Also, for testing, try just WS_OVERLAPPEDWINDOW and use ShowWindow() to show the window. If that works, then you know the flags are probably incorrect.
The first param to CreateWindow should be the classname, "PongAPP", in this case
as the AP above said, your first param must match the class you registered previously:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/createwindow.asp

This topic is closed to new replies.

Advertisement