The order in which messages are processed in the MFC Application
1. afxwndproc () This function is used to receive messages, locate the cwnd object to which the message belongs, and then call afxcallwndproc.
2. afxcallwndproc () This function is used to save messages (Message identifiers and message parameters are mainly saved) for future use by the application, and then calls the windowproc () function.
3. windowproc () this function is responsible for sending messages to the onwndmsg () function. If not processed, call the defwindowproc () function.
4. onwndmsg () The function first sorts messages by byte. For wm_command messages, the oncommand () Message response function is called, and the onnotify () Message response function is called for wm_notify messages. Any missed message is a window message. Onwndmsg () function searches for a message image to find a processing function that can process messages in any window. If the onwndmsg () function cannot find such a processing function, the message is returned to the windowproc () function, which sends the message to the defwindowproc () function.
5. oncommand () This function checks whether this is a control notification (the lparam parameter is not null. If the lparam parameter is null, the message is not a control notification). If it is, oncommand () the function tries to map messages to the control that creates notifications. If it is not a control notification (or if the control rejects the mapped message) oncommand (), it calls the on1_msg () function.
6. Based on the class that receives messages, the onreceivmsg () function potentially transmits command messages and control notifications in a process called command routing. For example, if the class that owns the window is a framework class, the command and notification messages are also transmitted to the view and document class, and a message processing function is found for the class.
The process of creating an MFC application window
1. precreatewindow () this function is an overload function. Before a window is created, you can change the creation parameters in this overload function (you can set the window style and so on)
2. presubclasswindow (), which is also an overload function that allows subclassification of a window.
3. ongetminmaxinfo () this function is a message response function that responds to wm_getminmaxinfo messages and allows you to set the maximum or minimum size of the window.
4. onnccreate () this function is also a message response function. It responds to the wm_nccreate message and sends a message to inform the customer zone of the window that will be created soon.
5. onnccalcsize () this function is also a message response function. It responds to the wm_nccalcsize message and allows you to change the size of the window client.
6. oncreate () this function is also a message response function. It responds to the wm_create message and sends a message to indicate that a window has been created.
7. onsize () this function is also a message response function that responds to the wm_size message and sends the message to indicate that the window size has changed.
8. The onmove () Message response function responds to the wm_move message. sending this message indicates that the window is moving
9. onchildnotify () this function is an overloaded function and is called as part of message ing, telling the parent window that a window has just been created
The order in which the MFC application closes the window (non-modal window)
1. onclose () Message response function. The wm_close message in the response window is sent when the close button is clicked.
2. ondestroy () Message response function, which refers to the wm_destroy message in the response window. When a window is destroyed, this message is sent.
3. onncdestroy () Message response function, which refers to the wm_ncdestroy message in the response window. This message is sent when a window is destroyed.
4. The postncdestroy () overload function is called by cwnd as the final action for processing the onncdestroy () function.
Order of function calls in the open mode dialog box in the MFC Application
1. domodal () overload function, overload domodal () member function
2. The presubclasswindow () overload function allows users to classify a window first.
3. The oncreate () Message response function responds to the wm_create message and sends this message to indicate that a window has been created.
4. The onsize () Message response function responds to the wm_size message and sends the message to notify the window size of the change.
5. The onmove () Message response function responds to the wm_move message and sends the message to notify the window that it is moving.
6. The onsetfont () Message response function responds to the wm_setfont message and sends the message to allow the font of the control in the dialog box to be changed.
7. The oninitdialog () Message response function responds to the wm_initdialog message and sends the message to allow the control in the initialization dialog box or create a new control.
8. The onshowwindow () Message response function responds to the wm_showwindow message, which is called by the showwindow () function.
9. The onctlcolor () Message response function responds to the wm_ctlcolor message. The color of the control in the changed dialog box or dialog box is sent by the parent window.
10. The onchildnotify () overload function is sent as the result of the wm_ctlcolor message.
Order of the close mode dialog box in the MFC Application
1. The onclose () Message response function responds to the wm_close message. When the "close" button is clicked, the function is called.
2. The onkillfocus () Message response function responds to the wm_killfocus message. It is sent when a window is about to lose the keyboard input focus.
3. The ondestroy () Message response function responds to the wm_destroy message. When a window is about to be destroyed, it is sent.
4. The onncdestroy () Message response function responds to the wm_ncdestroy message and is sent after a window is destroyed.
5. The postncdestroy () overload function is called by cwnd as the final action for processing the onncdestroy () function.
Order of opening the modeless dialog box
1. The presubclasswindow () overload function allows users to subclassify a window first
2. The oncreate () Message response function responds to the wm_create message and sends this message to indicate that a window has been created.
3. The onsize () Message response function responds to the wm_size message and sends the message to notify the window size of the change.
4. The onmove () Message response function responds to the wm_move message and sends the message to notify the window that it is moving.
5. The onsetfont () Message response function responds to the wm_setfont message and sends this message to allow the font of the control in the dialog box to be changed.
All the preceding operations are performed in the given order!
Only by clearly understanding the execution sequence of the application can you know when to write code, when to execute, and where to process it!
This is just a little bit of experience I have summarized. I hope it will help beginners of MFC! The order in which messages are processed in the MFC Application
The order of Message Processing in the MFC Program