GetMessage function
Namespace: Winuser.h
Header: Windows.h
Library: User32.lib
Syntax
BOOL GetMessage(
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax
);
Parameters
| Parameter | Type | Description |
|---|---|---|
| lpMsg | LPMSG | Pointer to an MSG structure that receives message information. |
| hWnd | HWND | Handle to the window whose messages are to be retrieved. If NULL, messages for any window belonging to the current thread are retrieved. |
| wMsgFilterMin | UINT | Smallest value of the range of message identifiers to be retrieved. If both filter parameters are zero, no filtering is performed. |
| wMsgFilterMax | UINT | Largest value of the range of message identifiers to be retrieved. |
Return Value
Returns non‑zero if a message other than WM_QUIT is retrieved; zero if the message is WM_QUIT; and -1 on error. Call GetLastError for extended error information when -1 is returned.
Remarks
GetMessageremoves the retrieved message from the thread's message queue.- Typical message loop:
MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } - Use
PeekMessagefor non‑blocking retrieval. - The function blocks until a message is available unless the thread has no messages and a
WM_QUITmessage is posted.
Requirements
Client: Windows 2000 or later.
Header: Windows.h (includes Winuser.h)
Library: User32.lib