Relationship between MFC templates, documents, views, and frameworks

Source: Internet
Author: User
[Reproduced from: http://soft.yesky.com/lesson/100/2342100.shtml]

We can summarize the contact information as follows:

(1) The document retains the View list of the document and the pointer to the document template that created the document. The document has at least one associated view, and the view can only be associated with one document.

(2) The view retains the pointer to its document and is contained in its parent frame window;

(3) The document Framework Window (I .e. the MDI child window containing the view) retains the pointer pointing to its current active view;

(4) The document template retains the list of open documents and maintains the ing of framework windows, documents, and views;

(5) The application retains the list of its document templates.

We can use a group of functions to make these classes accessible to each other. Table 6-1 lists these functions.

Table 6-1 mutual access between documents, document templates, views, and framework classes

From this object How to access other objects
Global Functions Call the global function afxgetapp to obtain the cwinapp application class pointer.
Application Afxgetapp ()-> m_pmainwnd is the frame window pointer; Use cwinapp: getfirstdoctemplatepostion, cwinapp: getnextdoctemplate to traverse all document templates
Document Call cdocument: getfirstviewposition, cdocument: getnextview to traverse all views associated with the document. Call cdocument: getdoctemplate to obtain the document template pointer.
Document Template Call cdoctemplate: getfirstdocposition, cdoctemplate: getnextdoc to traverse all corresponding documents
View Call cview: getdocument to obtain the corresponding document pointer. Call cview: getparentframe to obtain the Framework Window.
Document Framework Window Call cframewnd: getactiveview to obtain the pointer to the current active view. Call cframewnd: getactivedocument to obtain the document pointer appended to the current view.
MDI frame window Call cmdiframewnd: mdigetactive to obtain the MDI subwindow (cmdichildwnd) of the current activity)

Let's take an example to describe how to use the functions in the above table.CodeWhich provides the ability to traverse document templates, documents, and views:

Cmyapp * pmyapp = (cmyapp *) afxgetapp (); // get the applicationProgramPointer
Position P = pmyapp-> getfirstdoctemplateposition (); // get 1st document templates
While (P! = NULL) // traverse the Document Template
{
Cdoctemplate * pdoctemplate = pmyapp-> getnextdoctemplate (P );
Position p1 = pdoctemplate-> getfirstdocposition (); // obtain the 1st documents corresponding to the document template.
While (P1! = NULL) // traverse the document corresponding to the Document Template
{
Cdocument * pdocument = pdoctemplate-> getnextdoc (P1 );
Position P2 = pdocument-> getfirstviewposition (); // obtain the 1st views corresponding to the document.
While (P2! = NULL) // traverse the view corresponding to the document
{
Cview * pview = pdocument-> getnextview (P2 );
}
}
}

It can be seen that the following management relationships and implementation approaches are completely similar:

(1) apply to document templates;

(2) The document template is for the document;

(3) view the document.

Figure 6.1 and 6.2 respectively show the composition of a Multi-document/view framework MFC program and the hierarchy of the classes contained in the program.


Figure 6.1 composition of the Multi-document/view framework MFC Program


Figure 6.2 hierarchical relationship between document/view Framework Program classes

The relationship between documents and views can be further divided into three types:

(1) Documents correspond to multiple identical view objects, each of which is in a separate MDI document Framework Window;

(2) The document corresponds to multiple view objects of the same class, however, these view objects are in the same document Framework Window (through the "Split Window", the view space of a single document window is split into multiple separate document views );

(3) Documents correspond to multiple view objects of different classes. These view objects are only in a single MDI document Framework Window. In this model, multiple views constructed by different classes share a single frame window. Each view provides different ways to view the same document. For example, one view displays documents in word processing mode, and the other view displays documents in "document structure" mode.

Figure 6.3 shows the interface features of the corresponding three document and view relationship applications.


Figure 6.3 relationship between documents and views

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.