PostQuitMessage
Synopsis
VOID PostQuitMessage(
_In_ int nExitCode
);
Parameters
nExitCode | exit code to be returned to the system when the application terminates. |
---|
Return Value
This function does not return a value.
Remarks
Posts a WM_QUIT
message to the thread's message queue. This causes the GetMessage
function to return 0
and initiates the termination of the message loop.
Typical usage:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam; // or return nExitCode passed to PostQuitMessage
Examples
#include
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
MSG msg;
// Register class, create window, etc.
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}