I am not familiar with the message mechanism of MFC. It took me a day to look at Li Jiujin and Hou Jie.
I also searched some from the Internet, http://www.cppblog.com/nacci/category/1784.html
The comprehension and excerpt sections are as follows:
1. rtti mechanism. Every class defines a static variable, which contains the static variable address of the parent class, and then judges whether there is an inheritance relationship.
It's just a loop to judge the comparison of the parent class.
Bool cruntimeclass: isderivedfrom (const cruntimeclass * pbaseclass) const {// For simplicity, skip irrelevant code if (pbaseclass = NULL) return false; // simple Si case const cruntimeclass * pclassthis = This; while (pclassthis! = NULL) {If (pclassthis = pbaseclass) return true; pclassthis = pclassthis-> m_pbaseclass;} return false; // encoded ed to the top, no match}
2. Message ing: the message of MFC has not been clarified. Command, notify, reflect, and the set of distribution mechanism lines under the framework are confusing, in fact, you only need to find the source code. In the past, you could not find the specific code. The F12 and the line assist that comes with VC, such as cwnd: oncommand onpolicy, can only find the declaration, the specific definition is atlmfc \ SRC \ MFC \ wincore. CPP, read the code in it, at least the framework is clear
In fact, as long as the source code is identified, the problem is not big. MFC is relatively simple for several macros of the message, at least it is not difficult for people who are used to C code.
Begin_message_map
On_command
Ned_message_map
Through the run function of cwinthread, we can see that
Getmessagemap
Dispatchmessagemap
It can be seen that the message queue is actually managed by the thread, and according to the MSG provided by the operating system, the hwnd is returned, and then the wndproc function of the hwnd is called.
But how does this wndproc transmit messages between the parent and child windows?
The main difficulty of this message is policy. We know that the first message to be received is the mouse current window. How does the parent window get the response message, such as a button click event?
Originally, I understood that "The subwindow sends a notification message to the parent window after receiving the message". However, by reading the ondomainy code, this is not the case. It may be that it is processed internally in windows.
The message is sent, but does the onreceivy message only exist in the list of the parent window ?????
After receiving the message, the parent window calls the launch message and then processes it on its own.
Go around
Derived from csdnThe reply of visualeleven is clear. It seems that sometimes it is good to look at msdn.
Wm_notify and wm_command of the control are sent to the parent window of the control, which is processed by the parent window class.
Wm_notify:
Sent by a common control to its parent window when an event has occurred or the control requires some information.
Wm_command:
The wm_command message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.