The event-driven feature of Windows programs -- the core is the message

Source: Internet
Author: User

Messages are divided into inbound messages and non-Inbound messages. A message is sent to the queue dedicated to each thread by windows.ProgramSelf-processing, such messages are basically lost by users
(Wm_keydown, wm_keyup, wm_char, wm_mouse **, and wm_paint, wm_timer, wm_quit) or
The caller calls postmessage and the message generated by postthreadmessage. The so-called non-team message is the message directly sent to the window process, that is, directly calling the window
Other than the preceding messages!


Once a thread establishes at least one window, the system allocates a message queue to it. The main manifestation is that the system allocates a threadinfo structure for it, which has four pointers pointing to
Message Queue, message sending queue, Response Message queue, and virtual input queue. You can call postmessage or
Postthreadmessage. Other message queues are mainly used to process the following transactions. When a thread calls sendmessage to a window created by another thread, the first message sent is
First, it is appended to the sending message queue of the receiving thread. The sending thread is idle and waits for the receiving thread to return its message to the response queue of the sending thread after processing the message, wait until the sending thread is awakened to obtain the message in the response queue.

(That is, the return value after processing the message), continue to execute. The Virtual Input Queue is added to the corresponding thread by converting hardware events into messages by the Windows system thread rit (original input thread ).
In the virtual message queue.


The order in which message queues are processed. First of all, Windows does not process queues in the FIFO order, but has a certain priority. Priority is achieved by the Status mark of the message queue. First, the highest
The first level is the message sent by another thread (via sendmessage), the second is to register the Message Queue message, process the qs_quit mark again, process the virtual input queue, and then process
Wm_paint is finally wm_timer!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.