The relationship between the cmainframe class cdoc class cview class CAPP class in MFC

Source: Internet
Author: User

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

They are: Capp, cmainframe, cdoc, and cview.

Among them, the system is responsible for the management of the entire application. The cdoc class has a pointer to the process scheduler. It can also be considered that the application is executed from the process scheduler.

Cmainframe is the main window frame.

Cdoc is an application data source (document). It is mainly used to manage data and provides the function of saving and loading data. Read/write operations on files are performed in the serialize function of cdoc.

Cview is an application data display (view). It is mainly used for data display and provides users with data editing and modification functions. The data or graphics display operation is performed in the ondraw function of cview.

The basic application is composed of these four classes. All you need to do is instantiate these classes to implement the required functions.

On the SDI (Single Document) interface, the menu response follows the orderCmainframeClass receiving,CmainframeInstead of looking for corresponding functions internallyCviewClass. IfCviewClass has the response function of the message, then directly callCviewClass. Otherwise, goCdocClass, ifCdocClass, you can directly callCdocClass. OtherwiseCmainframeClass. IfCmainframeClass.CAPPClass. IfCAPPClass, indicating that no response function for the menu is found.

It can be understood that the order of the menu message response function is:Cview>Cdoc>Cmainframe>CAPP.

 

Call relationships between frameworks, documents, and view classes

1. Access view (cview) in the main framework (cframewnd)
Cview * getactiveview () const;
The commonly defined view is the derived class of cview. When you call the method of a custom view object

It should be written as follows: (cmousekeyview *) getactiveview ()-> myfunc ();

2. cdocument)
Getactivedocument, return the cdocument object;

3. Access the document (cdocument) in the view (cview)
Inline cmousekeydoc * cmousekeyview: getdocument ()
{Return (cmousekeydoc *) m_pdocument ;}

4. Access the framework (cframewnd) in the view (cview)
Cframewnd * getparentframe () const;

5. Access the framework (cframewnd) in the document (cdocument)
Cwnd * afxgetmainwnd ();
Cwnd * afxgetapp ()-> m_pmainwnd;

6. Access the view (cview) in the document (cdocument)
Updateallviews
Function: notifies all view documents of modified information.
Prototype:
Void updateallviews (
Cview * psender, // view pointer to be updated. If you want to update all views

Figure, set this parameter to null
Lparam lhint = 0l, // contains the notification for changing the message
Cobject * phint = NULL // the object that stores the change message
}

7. Access the document class (cdocument) in other classes)
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.