I don't think your message loop is correct. Try this:
Code:
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
I believe WM_QUIT will make GetMessage() return 0, which will then won't satisfy the condition in the while loop, so it should skip down to the return statement and end your program.
Alternatively, to allow for the error checking in GetMessage() (it returns -1 if there is any error), you could try something like this for your message loop:
Code:
int i;
while(1)
{
i = GetMessage(&msg, NULL, 0, 0);
if(i == -1) { /* Pop up a message box or something, there has been an error. */ }
else if(i == 0) { break; /* WM_QUIT has been received, break the loop. */ }
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;