There are two general scenarios
1. In the WinMain function, the last stage receives the message queue loop, and the GetMessage function parameter of the call provides an error
Such as:
while (GetMessage (&msg,hwnd, 0,0))
{
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
This error is often due to the negligence of the programmer, the individual compiler will have automatic completion (hint) function, will prompt the GetMessage function of the second parameter is an HWND type parameters, according to the habit, easy to write directly to the HWND, which is not right, in general, The second parameter is set to NULL, or null;
2, the message loop itself appears logic error
Such as:
while (TRUE)
{
if (GetMessage (&msg, NULL, 0, 0))
{
if (msg.message==wm_quit) {break;}
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
}
While the judgment part of the loop is always true, the program will not quit the process even if it accepts the exit message, which is a logic error and a programming habit, and it is generally recommended to put the return value of the GetMessage function directly into the while as a conditional statement to reduce errors.
Therefore, the correct wording should be written as:
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
return&msg.wparam;
Workaround for Windows programming about "Close window cannot quit process"