Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:docs:win16:api:user:postquitmessage [2026/02/18 02:03] – created prokushev | en:docs:win16:api:user:postquitmessage [2026/05/06 08:12] (current) – prokushev | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| {{page> | {{page> | ||
| - | ====== | + | ====== |
| ===== Brief ===== | ===== Brief ===== | ||
| + | |||
| + | The **PostQuitMessage** function posts a message to Windows indicating that an application is requesting to terminate execution (quit). This function is typically used in response to a `WM_DESTROY` message. | ||
| ===== Syntax ===== | ===== Syntax ===== | ||
| + | |||
| + | <code c> | ||
| + | VOID WINAPI PostQuitMessage(int nExitCode); | ||
| + | </ | ||
| ===== Parameters ===== | ===== Parameters ===== | ||
| + | |||
| + | * **nExitCode** — Specifies an application-defined exit code. It must be the **wParam** parameter of the `WM_QUIT` message. | ||
| ===== Return Code ===== | ===== Return Code ===== | ||
| + | |||
| + | This function does not return a value. | ||
| ===== Notes ===== | ===== Notes ===== | ||
| + | |||
| + | * The PostQuitMessage function posts a `WM_QUIT` message to the application and returns immediately; | ||
| + | * When the application receives the `WM_QUIT` message, it should exit the message loop in the main function and return control to Windows. | ||
| ===== Example Code ===== | ===== Example Code ===== | ||
| ==== C Binding ==== | ==== C Binding ==== | ||
| + | <code c> | ||
| + | #include < | ||
| + | |||
| + | LRESULT CALLBACK __export WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | ||
| + | { | ||
| + | switch (msg) | ||
| + | { | ||
| + | case WM_DESTROY: | ||
| + | PostQuitMessage(0); | ||
| + | return 0; | ||
| + | } | ||
| + | return DefWindowProc(hwnd, | ||
| + | } | ||
| + | |||
| + | int WINAPI WinMain(HANDLE hInstance, HANDLE hPrevInstance, | ||
| + | LPSTR lpCmdLine, int nCmdShow) | ||
| + | { | ||
| + | MSG msg; | ||
| + | |||
| + | /* ... window class registration and creation ... */ | ||
| + | |||
| + | while (GetMessage(& | ||
| + | { | ||
| + | TranslateMessage(& | ||
| + | DispatchMessage(& | ||
| + | } | ||
| + | |||
| + | return (int)msg.wParam; | ||
| + | } | ||
| + | </ | ||
| ==== MASM Binding ==== | ==== MASM Binding ==== | ||
| + | <code asm> | ||
| + | EXTRN PostQuitMessage: | ||
| + | |||
| + | WndProc PROC FAR | ||
| + | cmp ax, WM_DESTROY | ||
| + | je handle_destroy | ||
| + | ; ... other messages ... | ||
| + | |||
| + | handle_destroy: | ||
| + | push 0 ; nExitCode = 0 | ||
| + | call PostQuitMessage | ||
| + | xor ax, ax ; return 0 (message handled) | ||
| + | retf | ||
| + | WndProc ENDP | ||
| + | |||
| + | ; Message loop that catches WM_QUIT | ||
| + | WinMain PROC FAR | ||
| + | ; ... initialization ... | ||
| + | |||
| + | message_loop: | ||
| + | lea ax, msg | ||
| + | push ax ; lpMsg | ||
| + | push 0 ; hWnd | ||
| + | push 0 ; wMsgFilterMin | ||
| + | push 0 ; wMsgFilterMax | ||
| + | call GetMessage | ||
| + | cmp ax, 0 | ||
| + | je exit_app | ||
| + | |||
| + | lea ax, msg | ||
| + | push ax | ||
| + | call TranslateMessage | ||
| + | lea ax, msg | ||
| + | push ax | ||
| + | call DispatchMessage | ||
| + | jmp | ||
| + | |||
| + | exit_app: | ||
| + | mov ax, msg.wParam | ||
| + | retf | ||
| + | WinMain ENDP | ||
| + | </ | ||
| ===== See also ===== | ===== See also ===== | ||
| - | {{page>en:templates:win16}} | + | * [[en:docs:win16: |
| + | * [[en: | ||
| + | * [[en: | ||
| + | {{page> | ||




