PostMessage function

Posts a message to the message queue of the specified thread and returns without waiting for the thread to process the message.

Syntax

BOOL PostMessageA( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );

Parameters

ParameterDescription
hWndHandle to the window whose thread will receive the message. If this parameter is NULL, PostMessage posts the message to the message queue of the calling thread.
MsgMessage identifier. For example, WM_KEYDOWN or a custom message defined with RegisterWindowMessage.
wParamAdditional message-specific information. The content of this parameter depends on the value of Msg.
lParamAdditional message-specific information. The content of this parameter depends on the value of Msg.

Return value

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Example

The following example posts a WM_CLOSE message to a window identified by its handle.

#include <windows.h> int main() { HWND hWnd = FindWindowA(NULL, "Untitled - Notepad"); if (hWnd) { PostMessageA(hWnd, WM_CLOSE, 0, 0); } return 0; }

See also