I am using a special message loop for a custom dialog box. When the dialog box is open and the window is closed, I would like to reach the second if below, if(msg.message == WM_CLOSE).
for(;;)
{
if(PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
{
if(msg.message == WM_CLOSE)
{
GetMessage(&msg, 0, 0, 0);
break;
}
else
{
if(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == msgEnd)
break;
}
}
The problem is the code in this if is never reached. I tried replacing WM_CLOSE with another message to see if the loop was the problem, but the other message worked fine. What’s wrong?
It seems that WM_CLOSE is sent, and the other message is posted.
GetMessageandPeekMessageonly operate on posted messages (those posted withPostMessage). If a message is not posted but sent viaSendMessage, it’s handled immediately insidePeekMessageorGetMessage, so you can not getMSGstruct for it.