1. Message Queue (synchronously retrieve messages and actively query)
There are two types: Total message queue and form Message Queue:
I. Total system message queue
Obtain user operations from the input device and generate a total message queue.
2. Application (forms, including subforms and controls, collectively referred to as applications) Message Queue
Each application has its own message queue. The application registers its own message events to the total message queue as needed, then, the total Message Queue gets the final application to be distributed based on certain algorithms (including the processing mechanism, activity application, and form processing of various event messages, then, the messages in the total message queue are distributed to the corresponding message queue of the obtained application.
Each application has its own message loop, including actively obtaining messages from the form message queue, distributing messages, and processing messages.
When an application obtains a message, there are two situations:
You can obtain, distribute, process, and obtain messages in your message queue.
There is no message in your own message queue. Blocking waits for a message event in the message queue. There is no timeout here. A message is added to the message queue, which wakes up the newly blocked acquiring message thread and continues to get the message, distribute, process, and obtain again.
2. event registration (asynchronous message retrieval and passive notification)
The system has a total event table. Each table item corresponds to an event, and a linked list is mounted under each table item. This linked list is composed of all applications that register this message event. When a message event arrives, get the application to be notified in the linked list based on a certain algorithm, and then send the notification to the application for further distribution and processing.
All of the above are my personal understandings. If you have any mistakes or deviations, I hope you can give me more advice. At the same time, it is relatively simple to talk about. The specific implementation process is much more complicated than what we have mentioned, in addition, there are many situations that need to be taken into account. Here we just talk about a principle and a rough idea.