The Windows Messaging system is made up of 3 parts:
· Message Queuing. Windows can maintain a message queue for all applications. The application must get from the message queue
Message, and then assign it to a window.
· Message loops. This looping mechanism application retrieves a message from the message queue and assigns it to the appropriate window,
Continues to retrieve the next message from the message queue, and then assigns it to the appropriate window, in turn.
· Window procedure. Each window has a window procedure to receive the message that is passed to the window, and its task is to get the message and then
Respond to it. A window procedure is a callback function; After a message is processed, it usually returns a value to Windows.
Note that a callback function is a function in a program that is called by a Windows or external module.
A message is generated to be responded to by a window, which has 5 steps:
1) An event has occurred in the system.
2) Windows translates this event into a message and then puts it in the message queue.
3) The application receives this message from the message queue and stores it in the tmsg record.
4) The application passes the message to the window procedure for an appropriate window.
5) The window process responds to this message and processes it.
Steps 3 and 4 form the message loop for the application. Message loops are often at the heart of Windows applications because message loops
Enables an application to respond to external events. The task of the message loop is to retrieve the message from the message queue and then pass the message to the appropriate window. If there are no messages in the message queue, Windows allows other applications to process their messages.
The most important feature of the Windows operating system is its graphical interface, which is built on the basis of its message processing mechanism. If you do not understand the Windows Messaging mechanism, you will certainly not have a deep understanding of Windows programming. Unfortunately, many programmers are only slightly aware of Windows messages, the use of their knowledge is very little, but also do not know its internal implementation principle, this article tries step by step to disclose I understand the Windows message mechanism. Can say, mastered this part of the knowledge, is to master the Windows programming in the Divine Weapon, flexible use of it, will greatly improve our programming ability.
Windows Messaging Mechanism