Messages and Message Queues

July 15, 2025 ยท View on GitHub

This section describes messages and message queues and how to use them in your applications.

In This Section

NameDescription
About Messages and Message QueuesThis section discusses Windows messages and message queues.
Using Messages and Message QueuesThe following code examples demonstrate how to perform the following tasks associated with Windows messages and message queues.
Message ReferenceContains the API reference.

System-Provided Messages

For lists of the system-provided messages, see System-Defined Messages.

Message Functions

NameDescription
BroadcastSystemMessageSends a message to the specified recipients. The recipients can be applications, installable drivers, network drivers, system-level device drivers, or any combination of these system components.
To receive additional information if the request is defined, use the BroadcastSystemMessageEx function.
BroadcastSystemMessageExSends a message to the specified recipients. The recipients can be applications, installable drivers, network drivers, system-level device drivers, or any combination of these system components.
This function is similar to BroadcastSystemMessage except that this function can return more information from the recipients.
DispatchMessageDispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function.
GetInputStateDetermines whether there are mouse-button or keyboard messages in the calling thread's message queue.
GetMessageRetrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted message is available for retrieval.
Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning.
GetMessageExtraInfoRetrieves the extra message information for the current thread. Extra message information is an application- or driver-defined value associated with the current thread's message queue.
GetMessagePosRetrieves the cursor position for the last message retrieved by the GetMessage function.
To determine the current position of the cursor, use the GetCursorPos function.
GetMessageTimeRetrieves the message time for the last message retrieved by the GetMessage function. The time is a long integer that specifies the elapsed time, in milliseconds, from the time the system was started to the time the message was created (that is, placed in the thread's message queue).
GetQueueStatusIndicates the type of messages found in the calling thread's message queue.
InSendMessageDetermines whether the current window procedure is processing a message that was sent from another thread (in the same process or a different process) by a call to the SendMessage function.
To obtain additional information about how the message was sent, use the InSendMessageEx function.
InSendMessageExDetermines whether the current window procedure is processing a message that was sent from another thread (in the same process or a different process).
PeekMessageDispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message (if any exist).
PostMessagePosts 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.
PostQuitMessageIndicates to the system that a thread has made a request to terminate (quit). It is typically used in response to a WM_DESTROY message.
PostThreadMessagePosts a message to the message queue of the specified thread. It returns without waiting for the thread to process the message.
RegisterWindowMessageDefines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages.
ReplyMessageReplies to a message sent through the SendMessage function without returning control to the function that called SendMessage.
SendAsyncProcAn application-defined callback function used with the SendMessageCallback function. The system passes the message to the callback function after passing the message to the destination window procedure. The SENDASYNCPROC type defines a pointer to this callback function. SendAsyncProc is a placeholder for the application-defined function name.
SendMessageSends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.
SendMessageCallbackSends the specified message to a window or windows. It calls the window procedure for the specified window and returns immediately. After the window procedure processes the message, the system calls the specified callback function, passing the result of the message processing and an application-defined value to the callback function.
SendMessageTimeoutSends the specified message to one of more windows.
SendNotifyMessageSends the specified message to a window or windows. If the window was created by the calling thread, SendNotifyMessage calls the window procedure for the window and does not return until the window procedure has processed the message. If the window was created by a different thread, SendNotifyMessage passes the message to the window procedure and returns immediately; it does not wait for the window procedure to finish processing the message.
SetMessageExtraInfoSets the extra message information for the current thread. Extra message information is an application- or driver-defined value associated with the current thread's message queue. An application can use the GetMessageExtraInfo function to retrieve a thread's extra message information.
TranslateMessageTranslates virtual-key messages into character messages. The character messages are posted to the calling thread's message queue, to be read the next time the thread calls the GetMessage or PeekMessage function.
WaitMessageYields control to other threads when a thread has no other messages in its message queue. The WaitMessage function suspends the thread and does not return until a new message is placed in the thread's message queue.

Message Constants

NameDescription
OCM__BASEUsed to define private messages for use by private window classes.
WM_APPUsed to define private messages.
WM_USERUsed to define private messages for use by private window classes.

Message Structures

NameDescription
BSMINFOContains information about a window that denied a request from BroadcastSystemMessageEx.
MSGContains message information from a thread's message queue.