Your message loop is all wrong. The compiler is quite right that you are not initializing msg
. I'm not sure where you got that message loop from. Here's the standard one:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
If you want to use a non-blocking PeekMessage
based loop which seems popular for DirectX applications, it might look like this:
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// game code here
}
}
Notice that we initialise msg
before entering the while
loop which tests msg.message
.
Your other big problem is in your window procedure. You don't return the value that you get back from DefWindowProc
. The default
handler should look like this:
return DefWindowProc(hWnd, message, wParam, lParam);
Your broken window procedure is the reason why CreateWindowEx
fails. A broken window procedure is one of the classic failure modes for CreateWindowEx
.
Make these two changes and your program will work.
For people like Remy, who are worried about the fact that GetMessage
returns -1
when it fails, Raymond Chen explains why you don't need to worry about that, at least for this message loop.