Sign in to follow this  
Niddles

Hwnd is null?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The first param to CreateWindow should be the classname, "PongAPP", in this case

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this