Relationship between CMainFrame class CDoc class CView class CAPP Class in MFC

Source: Internet
Author: User
Tags assert

The application architecture claimed by the AppWizard tool includes four basic classes of applications,

respectively: Capp,cmainframe,cdoc,cview.

Where Capp is responsible for the management of the entire application, there is a CAPP pointer in the CDoc class, and the application can be thought to be executed from the CAPP.

CMainFrame is the main window frame

CDoc is an application data source (document) that is primarily used to manage data, providing the ability to save and load data. The read and write operation of the file is performed in the Serialize function of CDoc.

CView is the application Data display (view) is mainly used for data display, as well as to provide users with the ability to edit and modify the data. The display of data or graphics is done in the OnDraw function of CView.

The basic application is composed of these four classes. What users need to do is instantiate these classes to achieve the specific functionality they need.

In the SDI (single document) interface, the menu response follows a sequence in which the menu message is first received by the CMainFrame class, and CMainFrame is not directly looking for the corresponding function inside, but to the CView class. If the CView class has a response function for the message, then call the response function in the CView class directly, otherwise, go to the CDoc class and look for the response function in the CDoc class if the message is present, or return to the CDoc class to find it. If not in the CMainFrame class, return to the Capp class to find it. If it is not found in the Capp class, it indicates that there is no response function for the menu.

It can be understood that the order of menu message response functions is: Cview>cdoc>cmainframe>capp.

Call relationships between frames, documents, and view classes

1. Access view in main frame (CFrameWnd) (CView)
cview* GetActiveView () const;
Typically a defined view is a derived class of CView, when you invoke a method of the custom View object

It should be written like this: ((cmousekeyview*) GetActiveView ())->myfunc ();

2. Accessing the document (CDocument) in the main framework (CFRAMEWND)
GetActiveDocument, returns the CDocument object;

3. Accessing the document (CDocument) in the View (CView)
Inline cmousekeydoc* cmousekeyview::getdocument ()
{return (cmousekeydoc*) m_pdocument;}

4. Access frame (CFrameWnd) in view (CView)
cframewnd* getparentframe () const;

5. Accessing the framework in document (CDocument) (CFRAMEWND)
cwnd* AfxGetMainWnd ();
cwnd* AfxGetApp ()->m_pmainwnd;

6. Accessing the View (CView) in the document (CDocument)
UpdateAllViews
Function: Notifies all the information that the view document has been modified
Prototype:
void UpdateAllViews (
cview* Psender,//The view pointer to update, if you want to update all the viewing

Diagram, set this parameter to NULL
LPARAM lhint=0l,//notification with change message
cobject* Phint=null//storing objects that change messages
}

7. Accessing the document class in other classes (CDocument)
cdocument* GetDocument ()
{
cframewnd* frm= (cframewnd*):: AfxGetMainWnd ();
ASSERT (frm);
cdocument* pdoc=frm->getactivedocument ();
ASSERT (PDOC);
ASSERT (Pdoc->iskindof (Runtime_class (Cmousekeydoc)));
Return (cmousekeydoc*) PDoc;
}

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.