A detailed description of the--MFC encapsulation mechanism in Windows programming step

Source: Internet
Author: User

    • Single Document

At this time, there is only one dialog in the Resource's dialog box:

Run down to discover, here if the CRichEditView is selected:

If you click Save As, the suffix will appear here:

Let's look at its Class View:

What is the difference between a document and a view? A document has only one copy, and the view can have multiple copies, for example, for a txt it is a document:

But you can open n times:

Let's follow the code flow. Let's look at the app first, which is the class that characterizes the application, with its constructor as follows:

The definition of this class in its header file is as follows:

We can see in the app file:

This defines an app's own class, where we place breakpoints, and run, and so on, we step into the Theapp constructor:

But as we step in, we come to the CWinApp constructor:

This CWinApp is the parent of Theapp. This class has its own parent class:

So I stepped into the CWinThread constructor:

Step Into:

Step forward again to come:

There's nothing to do here, one step into its subclass, and then back to the subclass of subclasses, until we go back to:

Many steps have actually been performed. We step into, run to here:

But found in the Watch window that the this pointer is not CWinApp but his subclass:

Why?

See also: http://blog.csdn.net/ningyaliuhebei/article/details/42292147 's explanation. Because the object we are creating is mfcfirstsinefile, he will pass the address of the created object, that is, the address of the Theapp as a parameter to the Theapp constructor, and the Theapp constructor calls the CWinApp constructor first. The parameter passed to CWinApp is the address of Theapp.

The following is a class view to understand the MFC structure.

In CMainFrame, you perform some creation operations, such as creating toolbars, status bars:

Alt+g into the first oncreate you can also see that it creates help:

Then look at PreCreateWindow, which has a macro function:

Go into:

The form class is registered inside this function.

When you finish creating the form, you also hook it up:

The hook function hooks up the WH_CBT message:

This message is triggered when Windows activates, generates, releases (shuts down), minimizes, maximizes, or alters the window.

There's one behind:

Here is the implementation of the shortcut keys. In the resource view, we can also see these shortcut keys:

To proceed, execute to here:

A form has been updated:

But stuck can't move. Perform:

The entire form is displayed:

Go back and you'll see:

This function is to completely let the form run up. Let's look at the code:

There is no stopping to receive messages here. The pumpmessage in the top is executed:

After run, the program is up and running.

A detailed description of the--MFC encapsulation mechanism in Windows programming step

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.