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!