MFC "App, Doc, view class" differences and contact

Source: Internet
Author: User

MFC App,doc,mainframe,view each pointer to each other, first of all, the execution order of these four classes is App->doc->mainframe->view.

The App class is the SDI as the "program" entrance somewhat like the C language of the main () function.

The Document/view mode is to logically make the data and display separate.

In document, you define the member variables of the document class to save the data and display it with view.

In document, you can use UpdateAllViews () to notify view updates when the data for a member variable changes.

In view, the getdocument is used to obtain a pointer to the document, so that the member variables of the document can be accessed to display, Document/view is just a good support for you by MFC.

The view class is on top of the framework class, so if you need to implement a screen display, you can only respond in the view class.
Basically, a document class is a class for storing data management, whereas a view class is a class used to display data results, and they are generally associated,
Because they are closely related, a store, a display.

In addition, the app class and Doc class are derived from the CCmdTarget class, so you can only receive command messages and control notification messages. Both the view class and the frame framework class are derived from the CWnd class so they can receive command messages and control notification messages, as well as Windows message three messages. For three kinds of messages, the order of the responses is this:

First, the framework class receives the message, the framework class submits the message to its child window view, and if the view does not respond to the message, it is submitted to Doc by view, and if Doc does not respond to the message, it returns the message back to view. The view is then handed back to the frame frame, which checks to see if it has a corresponding handler for the message, and if not, it will be processed by the Windows system if it is not available to the app.
So another order problem. The definition of the Doc class will still be given back to the view class. Reference 1:

Reprint Source

The Doc class is the data storage class, your file import, open Display, save in this class, a view class corresponding to a doc, a doc can correspond to multiple view classes. The app doesn't really matter, it just creates an object that is the object of your program instance itself. View classes and Mainfram classes Note that the main focus is on the scope of their client area window, Mainfram indicates the entire frame of the instance, and view indicates the area under the toolbar (assuming there is only one view area). I don't know if you understand. No, about this paragraph you can refer to the xinxin Sun Teacher's video of the third speaking, it said in more detail. Reference 2:

DLG is the abbreviation for dialog, which represents the dialog box itself.

The App class is this SDI as the "program" of the entrance, a bit like C's main function, it is not derived from the CWnd. The app represents the application itself.

View represents a class of views that is responsible for displaying data, providing the ability to edit data and modify data. It means that the area inside the editor is the middle of the white area, which is responsible for drawing and responding to some messages.

Doc represents a document class that provides saving and loading of data. It's a bit like a database, it's saved with editing data, used for view redraw, and saved files.

The general dynamic editing data is placed in the doc. He is not derived from CWnd, and does not inherit the MessageBox function, you can use the AfxMessageBox function.

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.