Access relationships between frameworks in the MFC Document view

Source: Internet
Author: User

1. Document classes are usually related to data access and other processing processes. They are mainly used to represent document data, but each view must be attached to a framework (in SDI, it is attached to mainframe, attached to childframe in MDI). You can place the toolbar and menu on the frame;

2. some types of documents, frameworks, and views are associated with each other to form a document template class (the base class is cdoctemplate, and its sub-classes csingledoctemplate and cmutidoctemplate correspond to SDI and MDI ), the document template class is constructed during winapp initialization;

3. an app can have n document templates, but the SDI and MDI framework wizard generate only one template by default (if more templates are needed, they can be added similarly ); A document template can generate multiple document instances multiple times in a program, this so-called multi-Document Interface (multiple documents can be multiple documents of the same type or multiple different types); one data can have n forms of representation, therefore, a document can have n views associated with it;

4. There may be only one activity document, view, and framework at a specific time. That is, the current document, view, and framework. After understanding these operations, you can easily handle these problems.

 

Return values of interactive functions between MDI objects
Global afxgetapp cwinapp * (pointing to the current program)
Global afxgetmainwnd cwnd * (pointing to the main window framework of the Program)
Cmdiframewnd mdigetactive cmdichild WND * (pointing to the MDI subwindow of the current activity)
Cwnd getparentframe cframewnd * (pointing to the parent window frame)
Cframewnd getactiveview cview * (pointing to current activity view)
Cframewnd getactivedocument cdocument * (pointing to the current activity document)
Cview getdocument cdocument * (associated with this view class)
Cdocument getfirstviewposition: the first view class position in the View list related to the document
Cdocument getnextview the next View class position in the View list related to the document
E.g. cmainframe * mfrm = (cmainframe *) afxgetmainwnd ();

E.g.: Obtain the current view: cframewnd * pmain = (cframewnd *) afxgetmainwnd ();

Cframewnd * pchild = (cframewnd *) pmain-> getactiveframe ();

Cview * m_pagentview = (cview *) pchild-> getactiveview (); L

Access the current activity view and activity document.

For SDI programs, the main framework window is the document window. You can use the following methods to obtain the current document and view:

Obtain the activity document: cmydocument * pdoc;

Pdoc = (cmydocument *) (cframewnd *) afxgetapp ()-> m_pmainwnd)-> getactivedocument ();

Or pdoc = (cmydocument *) (cframewnd *) afxgetmainwnd (); the two are equivalent.

Get activity View:

Cmyview * pview; pview = (cmyview *) (cframewnd *) afxgetapp ()-> m_pmainwnd)-> getactiveview ();

 

For an MDI program, because the child window is the document window, you must first use getactiveframe () to obtain the activity child frame window, and then obtain the activity document and view through the Child window:

Cmdichildwnd * pchild = (cmdichildwnd *) (cframewnd *) afxgetapp ()-> m_pmainwnd)-> getactiveframe ();

Get activity documents:

Cmydocument * pdoc = pchild-> getactivedocument ();

Cmyview * pview = (cmyview *) pchild-> getactiveview ();

You can make the preceding function snippet a static member function, for example:

Static cmydocument: getcurrentdoc ()

{

Cmdichildwnd * pchild = (cmdichildwnd *) (cframewnd *) afxgetapp ()-> m_pmainwnd)-> getactiveframe ();

Cmydocument * pdoc = pchild-> getactivedocument ();

}

In this way, you can obtain the activity document (or view) in the following ways ):

Cmydocument: getcurrentdoc ();

Note: When calling a static member function, you do not need to associate a specific object with it.

Document Template:

Cmultidoctemplate * pdoctmpl;

Pdoctmpl = (cimpapp *) afxgetapp ()-> m_pdoctemplate;

Position posdoc = pdoctmpl-> getfirstdocposition ();

While (null! = Posdoc) {pfrmdoc = (cfrmdoc *) pdoctmpl-> getnextdoc (posdoc); ndocorder ++ ;}

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.