PostMessageA function (winuser.h)
Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.
To post a message in the message queue associated with a thread, use the PostThreadMessage function.
BOOL PostMessageA( [in, optional] HWND hWnd, [in] UINT Msg, [in] WPARAM wParam, [in] LPARAM lParam );
[in, optional] hWnd
A handle to the window whose window procedure is to receive the message. The following values have special meanings.
||The message is posted to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows. The message is not posted to child windows.|
||The function behaves like a call to PostThreadMessage with the dwThreadId parameter set to the identifier of the current thread.|
Starting with Windows Vista, message posting is subject to UIPI. The thread of a process can post messages only to message queues of threads in processes of lesser or equal integrity level.
The message to be posted.
For lists of the system-provided messages, see System-Defined Messages.
Additional message-specific information.
Additional message-specific information.
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. GetLastError returns ERROR_NOT_ENOUGH_QUOTA when the limit is hit.
When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).
Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.
The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= WM_USER) to another process, you must do custom marshalling.
If you send a message in the range below WM_USER to the asynchronous message functions (PostMessage, SendNotifyMessage, and SendMessageCallback), its message parameters cannot include pointers. Otherwise, the operation will fail. The functions will return before the receiving thread has had a chance to process the message and the sender will free the memory before it is used.
An accessibility application can use PostMessage to post WM_APPCOMMAND messages to the shell to launch applications. This functionality is not guaranteed to work for other types of applications.
A message queue can contain at most 10,000 messages. This limit should be sufficiently large. If your application exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the following registry key.
HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows NT CurrentVersion Windows USERPostMessageLimit
The minimum acceptable value is 4000.
The following example shows how to post a private window message using the PostMessage function. Assume you defined a private window message called WM_COMPLETE:
#define WM_COMPLETE (WM_USER + 0)
You can post a message to the message queue associated with the thread that created the specified window as shown below:
WaitForSingleObject (pparams->hEvent, INFINITE) ; lTime = GetCurrentTime () ; PostMessage (pparams->hwnd, WM_COMPLETE, 0, lTime);
For more examples, see Initiating a Data Link.
The winuser.h header defines PostMessage as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
|Minimum supported client||Windows 2000 Professional [desktop apps only]|
|Minimum supported server||Windows 2000 Server [desktop apps only]|
|Header||winuser.h (include Windows.h)|
|API set||ext-ms-win-ntuser-message-l1-1-0 (introduced in Windows 8)|