This is my main loop:
while(TRUE)
{
PeekMessage(&msg,hWnd,0,0,PM_REMOVE);
if (msg.message==WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
and this is my callback procedure:
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg1,WPARAM wParam,LPARAM lParam)
{
switch(msg1)
{
case WM_DESTROY :
{
PostQuitMessage(0);
return 0;
}
break;
}
return DefWindowProc(hWnd,msg1,wParam,lParam);
}
I found out that when I press Close button WM_NCLBUTTONDOWN will be returned by the PeekMessage function in the next loop, and no WM_QUIT!
The correct way to do a message loop is
You can use
PeekMessageif you really need to… but why are you ignoring the return value?Also, note that this is specific to a window. I believe
PostQuitMessageis for a thread… I don’t remember it off the top of my head, but you might need to passNULLinstead ofhWnd.If you have any other windows, that may hijack their message loop as well — I don’t think it’s usually an issue, but it might potentially be one; keep that in mind.