I. Windows Messaging mechanism processing process
(1) Windows establishes a message queue for each executing Windows application, which is the application queue that holds messages for various windows that the program may create.
When an application event occurs, Windows translates the event into a message and puts the message in the application's message queue.
(2) The application retrieves event messages from the message queue via GetMessage and distributes them to the message handlers of the corresponding window.
while 0 0 ) {// Converts a virtual key message to a character message translatemessage (&msg); // Pass the MSG structure back to Windows and Windows will // the message is sent to the appropriate window message handler function DispatchMessage (&msg); }
Two. Windows Messaging Mechanism essentials
(1) Window procedure
Each window will have a callback function called a window procedure (WNDPROC), and the system will call back with this window procedure to process the message when the window receives the message
(2) Message type
Message types are divided into system-defined messages (window messages, command messages, control notification messages), and user-defined messages
A. Window message: Related to the internal workings of the window, such as window creation, drawing, display, destruction, etc.
B. Command message: Related to handling user requests, such as clicking a menu item or toolbar or control
C. Control notification: WM_NOTIFY message, most flexible message format
D. User-defined message Wm_user + 100 (habitual)
(3) Message Queuing
A. System Message Queuing
B. Thread Message Queuing: Each GUI thread maintains such a thread message queue. This queue is only created when the thread calls the GDI function, and the default part is created
The message in the thread message queue is then sent to the appropriate window procedure for processing.
Note: wm_paint, wm_time in thread Message Queuing will only be processed if there are no other messages in the queue
Windows Messaging Mechanism