Message is the core of event-driven windows!

Source: Internet
Author: User
Message is the core of event-driven windows!

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. This type of message is basically generated by user input (wm_keydown, wm_keyup, wm_char, wm_mouse **, and wm_paint, wm_timer, wm_quit) or messages generated by calling postmessage, postthreadmessage; the so-called non-team message is the message that is directly sent to the window process, that is, the process of directly calling the window. This type is generally exclusive to the above messages!

Once a thread establishes at least one window, the system allocates a message queue to it. The main form is to assign a threadinfo structure to the system. The structure has four pointers to register message queues, send message queues, reply message queues, and Virtual Input Queues respectively. To add a message to the registration message queue, you can call postmessage or postthreadmessage. Other message queues are mainly used to process the following transactions. When a thread calls a sendmessage window created by another thread, the sent message is first appended to the sending message queue of the receiving thread, and the sending thread is idle, wait until the receiving thread finishes processing his message and returns it to the response queue of the sending thread. After that, the sending thread is awakened to obtain the message in the response queue (that is, the return value of the message after processing) and continue execution. The Virtual Input Queue is a Windows system thread, rit (original input thread), responsible for converting hardware events into messages and adding them to the virtual message queue of the corresponding thread.

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. The highest priority is the messages sent by other threads (via sendmessage), the second is to register the Message Queue message, process the qs_quit mark again, and then process the virtual input queue, wm_paint is finally wm_timer!

Related Article

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: 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.