1. command routing: when a message comes in, a pump pushes it forward. how messages come in and how they are pushed by pump functions are all part of Windows program design. If a message is routed from a subclass to the parent class (vertical flow), it will be easier, the entire message map message ing table has been clearly planned. messages should have the opportunity to flow horizontally. The MFC rules for message loops are as follows:
If it is a common Windows message (wm_xxx), it must be from the derived class stream to the base class, there is no possibility of the next stream.
If it is a command message (wm_command), there will be a strange route.
2. Message ing-window message
Defwindowproc --> afxwndproc --> afxcallwndproc --> pwnd-> windowproc
When a message reaches pwnd-> windowproc (), it calls cwnd: windowproc () and then calls onwndmsg (message, wparam, lparam, & lresult );
In the onwndmsg () function, determine the current message, wm_command, wm_notify, and standard Windows messages respectively.
If it is a wm_command message, it can be divided into command messages and control notification messages from the window. If it is a command message that calls on1_msg () directly, this function is a virtual function. First, the on1_msg of the dialog box is called, in the on1_msg method of the dialog box itself, the on1_msg method of the base class cdialog, cwnd, and c1_target will be called in sequence. Among them, the on1_msg method of c1_target mainly searches for the message ing table, if the corresponding processing function is found, call the _ afxdispatchreceivmsg method to execute the message processing function in the message ing table .... if it is a control notification message, it is used to determine the passed hwndctrl! = NULL. If it is true, it is the control notification message. The reflectlastmsg (hwndctrl) function is called first to reflect the message to the control itself.
Reflectlastmsg (hwndctrl) is first called for both wm_notify messages and notifications from controls of wm_command)
Next, let's look at Message reflection: reflectlastmsg () is preferentially called in the wm_command for Command Message Processing and wm_notify for notification message processing. The call sequence is: pwnd-> sendchildnotifymsg (presult) -> return onchildnotify-> .... _> return reflectchildnotify () This function actually implements Message reflection. It sends the reflected message wm_command + wm_reflect_base or wm_notify + wm_reflect_base, which is finally sent to the on1_msg plenary session. As mentioned below, this is a virtual function. First, the on1_msg of the dialog box is called. In the on1_msg method of the dialog box itself, the on1_msg method that causes the base class cdialog, cwnd, and c1_target classes is called in sequence (search the message ing table, directly call the message ing function );
Added by xiejl