GetMessageW Function

Retrieves messages from the calling thread's message queue.

Syntax

BOOL GetMessageW(
    LPMSG lpMsg,
    HWND hWnd,
    UINT wMsgFilterMin,
    UINT wMsgFilterMax
);

Parameters

Return Value

If the function succeeds, the return value is non-zero. If the function retrieves a quit message (when wMsgFilterMin and wMsgFilterMax are both zero), the return value is zero. If there is an error, the return value is -1.

Remarks

The GetMessageW function retrieves a message from the message queue of the calling thread and places the message in the structure pointed to by the lpMsg parameter.

Note: If you are retrieving messages for a specific window, you should pass the window's handle (hWnd) to GetMessageW. If you are retrieving messages for any window belonging to the thread, pass NULL for hWnd.

See Also

Tip: This function is typically called in a message loop to process Windows messages. A common message loop looks like this:

MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}