Overviews
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 Microsoft Windows messages and message queues.
Functions
BroadcastSystemMessageThe BroadcastSystemMessage function sends 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.
BroadcastSystemMessageExThe BroadcastSystemMessageEx function sends 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.
DispatchMessageThe DispatchMessage function dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function.
GetInputStateThe GetInputState function determines whether there are mouse-button or keyboard messages in the calling thread's message queue.
GetMessageThe GetMessage function retrieves 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.
GetMessageExtraInfoThe GetMessageExtraInfo function retrieves 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.
GetMessagePosThe GetMessagePos function retrieves the cursor position for the last message retrieved by the GetMessage function.
To determine the current position of the cursor, use the GetCursorPos function.
GetMessageTimeThe GetMessageTime function retrieves 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).
GetQueueStatusThe GetQueueStatus function indicates the type of messages found in the calling thread's message queue.
InSendMessageThe InSendMessage function determines 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.
InSendMessageExThe InSendMessageEx function determines whether the current window procedure is processing a message that was sent from another thread (in the same process or a different process).
PeekMessageThe PeekMessage function dispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message (if any exist).
PostMessageThe PostMessage function 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 associate with a thread, use the PostThreadMessage function.
PostQuitMessageThe PostQuitMessage function indicates to the system that a thread has made a request to terminate (quit). It is typically used in response to a WM_DESTROY message.
PostThreadMessageThe PostThreadMessage function posts a message to the message queue of the specified thread. It returns without waiting for the thread to process the message.
RegisterWindowMessageThe RegisterWindowMessage function defines a new window message that is guaranteed to be unique throughout the system. The message value can be used when sending or posting messages.
ReplyMessageThe ReplyMessage function is used to reply to a message sent through the SendMessage function without returning control to the function that called SendMessage.
SendAsyncProcThe SendAsyncProc function is an 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.
SendMessageCallbackThe SendMessageCallback function sends 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.
SendNotifyMessageThe SendNotifyMessage function sends 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.
SetMessageExtraInfoThe SetMessageExtraInfo function sets 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.
TranslateMessageThe TranslateMessage function translates 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.
WaitMessageThe WaitMessage function yields 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.
Notifications
OCM__BASEThe OCM__BASE constant is used by applications to help define private messages for use by private window classes, usually of the form OCM__BASE+X, where X is an integer value.
WM_APPThe WM_APP constant is used by applications to help define private messages, usually of the form WM_APP+X, where X is an integer value.
WM_QUITThe WM_QUIT message indicates a request to terminate an application and is generated when the application calls the PostQuitMessage function. It causes the GetMessage function to return zero.
WM_USERThe WM_USER constant is used by applications to help define private messages for use by private window classes, usually of the form WM_USER+X, where X is an integer value.