发表于2008/10/2 19:44:00 432人阅读
在队列消息中WM_PAINT message, the WM_TIMER message, and the WM_QUIT message三种消息是被放在消息队列的队尾的，以确保其他消息的FIFO特性。线程通过GetMessage 从线程消息队列中移除消息， 通过 驱使系统将消息发送到相应的窗口过程。
The system uses two methods to route messages to a window procedure: posting messages to a first-in, first-out queue called a message queue, a system-defined memory object that temporarily stores messages, and sending messages directly to a window procedure.
Messages posted to a message queue are called queued messages. They are primarily the result of user input entered through the mouse or keyboard, such as , , , and messages. Other queued messages include the timer, paint, and quit messages: , WM_PAINT, and . Most other messages, which are sent directly to a window procedure, are called nonqueued messages.
The system can display any number of windows at a time. To route mouse and keyboard input to the appropriate window, the system uses message queues.
The system maintains a single system message queue and one thread-specific message queue for each graphical user interface (GUI) thread. To avoid the overhead of creating a message queue for non–GUI threads, all threads are created initially without a message queue. The system creates a thread-specific message queue only when the thread makes its first call to one of the User or Windows Graphics Device Interface (GDI) functions.
Whenever the user moves the mouse, clicks the mouse buttons, or types on the keyboard, the device driver for the mouse or keyboard converts the input into messages and places them in the system message queue. The system removes the messages, one at a time, from the system message queue, examines them to determine the destination window, and then posts them to the message queue of the thread that created the destination window. A thread's message queue receives all mouse and keyboard messages for the windows created by the thread. The thread removes messages from its queue and directs the system to send them to the appropriate window procedure for processing.
With the exception of the WM_PAINT message, the WM_TIMER message, and the WM_QUIT message, the system always posts messages at the end of a message queue. This ensures that a window receives its input messages in the proper first in, first out (FIFO) sequence. The WM_PAINT message, the WM_TIMER message, and the WM_QUIT message, however, are kept in the queue and are forwarded to the window procedure only when the queue contains no other messages. In addition, multiple WM_PAINT messages for the same window are combined into a single WM_PAINT message, consolidating all invalid parts of the client area into a single area. Combining WM_PAINT messages reduces the number of times a window must redraw the contents of its client area.
The system posts a message to a thread's message queue by filling an structure and then copying it to the message queue. Information in MSG includes: the handle of the window for which the message is intended, the message identifier, the two message parameters, the time the message was posted, and the mouse cursor position. A thread can post a message to its own message queue or to the queue of another thread by using the or function.
An application can remove a message from its queue by using the function. To examine a message without removing it from its queue, an application can use the function. This function fills MSG with information about the message.
After removing a message from its queue, an application can use the function to direct the system to send the message to a window procedure for processing. DispatchMessage takes a pointer to MSG that was filled by a previous call to the GetMessage or PeekMessage function. DispatchMessage passes the window handle, the message identifier, and the two message parameters to the window procedure, but it does not pass the time the message was posted or mouse cursor position. An application can retrieve this information by calling the and functions while processing a message.
A thread can use the function to yield control to other threads when it has no messages in its message queue. The function suspends the thread and does not return until a new message is placed in the thread's message queue.
You can call the function to associate a value with the current thread's message queue. Then call the function to get the value associated with the last message retrieved by the GetMessage or PeekMessage function.
Nonqueued messages are sent immediately to the destination window procedure, bypassing the system message queue and thread message queue. The system typically sends nonqueued messages to notify a window of events that affect it. For example, when the user activates a new application window, the system sends the window a series of messages, including , , and . These messages notify the window that it has been activated, that keyboard input is being directed to the window, and that the mouse cursor has been moved within the borders of the window. Nonqueued messages can also result when an application calls certain system functions. For example, the system sends the message after an application uses the function to move a window.
Some functions that send nonqueued messages are , , , , and .
kanbozhang 2010-03-17 13:31 26
中央电视台最常用的 100 首经典背景乐曲（视频制作音乐推荐） 2009-05-12 17:31:47
neubuffer 2013-11-23 14:22 1411
shinewithyou 2017-05-31 22:29 46
toto1297488504 2015-08-02 23:39 1849
技术的延续---WMS (2008-05-28 14:34)
eric474470 2012-06-20 17:30 704
RabbitMQ （消息队列）专题学习05 routing(路由)
u014548782 2014-05-06 23:48 1095
11种4阶环、9阶环、25阶环、49阶环，22种12阶环(2015-11-12 14:45:07)、18阶环、20阶环、28阶环(2015-11-22 09:31)
u010401391 2015-12-03 10:09 442
关于RTF(富文本格式)的使用 (2008-12-14 13:59:11)转载
huixx 2011-09-05 17:21 1289