Record some previously Vague understandings of MFC

Source: Internet
Author: User

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.




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.