What is the differences between
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
and
case WM_DESTROY:
PostQuitMessage(0);
break;
?
When you call PostQuitMessage, you pass an exit code, not a message ID. PostQuitMessage will in turn generate (and post) the WM_QUIT message for you.
So technically, the difference is that with PostQuitMessage(WM_QUIT), the exit code will be 0x0012 (or 18 in decimal). Whereas PostQuitMessage(0) will provide an exit code of 0.
When either GetMessage and PeekMessage see a WM_QUIT message, they will return zero, and you can check for the exit code in the WPARAM part of the LPMSG parameter.
To return the exit code (the value you pass to PostQuitMessage) the message pump for your application could be something like this:
MSG msg;
while (0 != GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
We can find code, on which the message loop is discontinued on an "error" of -1 from GetMessage(). So if the application in this case suddenly disappears, no shocked user will find out what the reason for this was. The better way is to keep the app running. And also a "bad" message does not damage the DefWindowProc() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With