Document view Structure Analysis

Source: Internet
Author: User
Document view Structure Analysis

Theapp is a unique global variable. Its main function is to start the program by calling the encapsulated winmain main function.

Shows the relationship between the main objects of an MFC application based on the document view framework.

1In the main framework (Cframewnd) To access the view (Cview)

Getactiveview ()

Function: return the cview object of the activity.

Prototype: cview * getactiveview () const;

Note: The commonly used view is a cview derived class. before using the function in the derived class, you need to perform a type conversion, for example (cxxxview *) getactiveview ()-> myfunction ();

This problem is caused by the parent class pointer and subclass pointer.

2In the View (Cview) To access the main framework (Cframewnd)

Getparentframe ()

Function: return the cview object of the activity.

Prototype: cframewnd * getparentframe () const;

Note: the easiest way to obtain the main framework in a view is this.

3In the View (Cview) To access the Document Object (Cdocumet)

Getdocument ()

Function: obtains the document pointer of a view.

Prototype: cw.net * getdocument () const;

Note: If you use Wizard to generate a document view structure, VC will automatically generate code similar to the following based on the project:

# Ifndef _ debug

Inline cxxxdoc * cxxxview: getdomainnet ()

{Return (cxxxdoc *) m_pdocument ;}

# Endif

4In the document (Cdocument).View (Cview)

Updateallviews (null)

Function: notifies all views that the document object has been modified.

Prototype: void updateallviews (

Cview * psender, // view pointer to be updated. If all views are updated, the value is set to null.

Lparam lhint = 0l, // contains the notification for changing the message

Cobject * phint = NULL)

Note: Generally, updateallviews (null) is used to call the onupdate () virtual function of all views associated with the current document object.

Cdocument: addview

Function: Creates a connection between a view object and a Document Object (adds the view to a linked list and points the document pointer of the view to the document ).

Cdocument: getfirstviewposition () cdocument: getnextview (POS)

Function: Used to traverse view objects.

5Document Template object Create Document Object

Csingledoctemplate () cmultidoctemplate ()

Function: the framework uses constructors to generate document objects and connects documents, frameworks, and views.

6Document Object Access Document Template object

Getdoctemplate () getfirstdocposition () getnextdoc (POS)

Function: in SDI, only one document object can be created for a document template. The two correspond One to One. Therefore, you can use getdoctemplate () to obtain a pointer to the document template. In MDI, A document template can create multiple document objects. Each document template instance maintains a Document Object List to store the associated document objects. getfirstdocposition () getnextdoc (POS) traverse all documents.

7Use less

8Document Template object Create Frame window object

Csingledoctemplate () cmultidoctemplate ()

Function: the framework uses constructors to generate document objects and connects documents, frameworks, and views.

9Application Object PassCdocmanagerManagement Document Template object

10Application Object InInitinstance ()Create Document Template object

 

 

 

 

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.