MFC message ing mechanism

Source: Internet
Author: User

1. Function of the message loop
Cwinapp: Run

2. Message category
<1> Windows messages
Wm_xx prefix, except for wm_command messages.
<2> control events
Contains the wm_command notification message sent from the control or subwindow to the parent window.
<3> command messages
Menu, toolbar button, shortcut key


3. Send and accept messages
Cwinapp: The run function receives messages and distributes them to appropriate windows. Most command messages are sent to the main framework window. The receiving message must be a window object. If it is a Windows message, it is directly processed by the window object. If it is a command message, it is processed according to the message routing.
<1> standard Windows messages
Unlike command messages, a message is directly processed by a window sent by a message. The window can be mainframe, MDI childwindow, standard control, dialog, view, or child windows.

During running, each window is associated with a window object (Z is derived directly or indirectly from cwnd), and then the framework uses message ing to send messages to the processing function for processing.


<2> Command Message

After the command messages is accepted by the main framework, it depends on the message routing mechanism to find the final processing function. The so-called message routing means that the message is transmitted from one command target to another in a specified path, the so-called Command target of the message is the candidate object of some columns to be passed by the framework during message routing. These candidate objects are Command target (Command target)

4. standard message routing
_____________________________________________________________________________________
MDI frame (cmdiframewnd)
Active Cmdichildwnd
This framewnd window
Application (cwinapp object)
_____________________________________________________________________________________
Document frame window (cframewnd, cmdichildwnd)
Active View
This frame window
Application (cwinapp object)
______________________________________________________________________________________
View
This view
Document attached to this view
______________________________________________________________________________________
Document
This document
Document Template attached to this document
______________________________________________________________________________________
Dialog
This dialog
Window that owns this dialog
Application (cwinapp object)
______________________________________________________________________________________


5 ondomainmsg
It determines whether there are functions for processing commands, and sends the commands to the next level of on1_msg. It can be overloaded to change the default message routing.
Here, we will check the message ing macro and check whether there are corresponding processing functions in the message ing macro.


6. message routing of the derived class
If any of the unmatched values is found in the derived class, find the base class, and so on. If no handler is found at the end, execute the default handler.
<1> for command messages, go to the next command target
<2> if it is a standard Windows message, it is passed to the default window procedure function.
The message ing mechanism has the functions of virtual functions, but it saves space than virtual functions. To accelerate message ing, the Framework caches the latest matching.


7 message-MAP range
Bind multiple messages to the same processing function
<1> on_command_range (startid, endid, & onxxxfunc) // ID must be continuous
<2> on_update_command_ui_range (startid, endid, & onxxxfunc)

<3> on_control_range (notification, startid, endid, & onxxxfunc)


8. Heavy Load of standard Windows messages
During overload, the base class function may be called at the beginning or end or not.

Conclusion: The message ing mechanism of window is generally
The sent message contains a window handle. Each window handle is associated with a window object. Cwinapp: The run function is a message loop function that sells messages and sends messages. On1_msg finds the function for processing messages in the message ing macro, which processes messages according to different categories. If a command message is sent, the message is processed step by step according to the message routing. If a non-command message is sent, the message is delivered to the window object for processing.

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: info-contact@alibabacloud.com 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.