您的位置:首页 > 编程语言 > C语言/C++

VC++ Messages and Message Queues

2009-04-08 19:59 579 查看
Messages and Message Queues

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

Overviews

About Messages and Message Queues
This section discusses Windows messages and message queues.

Using Messages and Message Queues
The following code examples demonstrate how to perform the following tasks associated with Microsoft Windows messages and message queues.

Functions

BroadcastSystemMessage
The 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.

BroadcastSystemMessageEx
The 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.

DispatchMessage
The DispatchMessage function dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function.

GetInputState
The GetInputState function determines whether there are mouse-button or keyboard messages in the calling thread's message queue.

GetMessage
The 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.

GetMessageExtraInfo
The 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.

GetMessagePos
The 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.

GetMessageTime
The 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).

GetQueueStatus
The GetQueueStatus function indicates the type of messages found in the calling thread's message queue.

InSendMessage
The 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.

InSendMessageEx
The 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).

PeekMessage
The PeekMessage function dispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message (if any exist).

PostMessage
The 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.

PostQuitMessage
The 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.

PostThreadMessage
The PostThreadMessage function posts a message to the message queue of the specified thread. It returns without waiting for the thread to process the message.

RegisterWindowMessage
The 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.

ReplyMessage
The ReplyMessage function is used to reply to a message sent through the SendMessage function without returning control to the function that called SendMessage.

SendAsyncProc
The 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.

SendMessage
Sends 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.

SendMessageCallback
The 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.

SendMessageTimeout
Sends the specified message to one of more windows.

SendNotifyMessage
The 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.

SetMessageExtraInfo
The 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.

TranslateMessage
The 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.

WaitMessage
The 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__BASE
The 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.

Note Unlike WM_APP and WM_USER, OCM__BASE is defined in Olectl.h.
WM_APP
The 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_QUIT
The 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_USER
The 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.

Structures

BSMINFO
The BSMINFO structure contains information about a window that denied a request from BroadcastSystemMessageEx.

MSG
The MSG structure contains message information from a thread's message queue.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: