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;
}
Hwnd is null?
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.
Can someone help me out here?
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
-AJ
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
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.
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.
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.
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
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
Popular Topics
Advertisement