"VC + + Learning Note Four" framework class acquisition in MFC applications

Source: Internet
Author: User

First, the document class

Get view:

Get the main form first, and get the view based on the main form

Pmain->getactivedocument (); Note Type conversions

Because the document may contain multiple views, it can be obtained by using the following function:

cview* Ctestdoc::getview (cruntimeclass* pClass)

{

cview* PView;

POSITION pos=getfirstviewposition ();

while (Pos!=null)

{

Pview=getnextview (POS);

if (!pview->iskindof (PClass))

Break

}

if (!pview->iskindof (PClass))

{

AfxMessageBox ("Connt Locate the view./r/n");

return NULL;

}

return pView;

}

Similarly, if you have multiple views, the way to get another view in one view is as follows:

cview* Ctestaview::getview (cruntimeclass* pClass)

{

ctestdoc* pdoc= (ctestdoc*) getdocument ();

cview* PView;

POSITION pos=pdoc->getfirstviewposition ();

while (Pos!=null)

{

Pview=pdoc->getnextview (POS);

if (!pview->iskindof (PClass))

Break

}

if (!pview->iskindof (PClass))

{

AfxMessageBox ("Connt Locate the View.");

return NULL;

}

return pView;

}

Get main form:

CMainFrame *pmain = (CMainFrame *) AfxGetMainWnd ();

Get the app first, then get the main form based on the app

Cxxxapp *papp = (Cxxxapp *) AfxGetApp ();

CMainFrame *pmain = (cmainframe*) Papp->getmainwnd ();

CMainFrame *pmain = (cmainframe*) papp->m_pmainwnd;

Get app:

Cxxxapp *papp = (Cxxxapp *) AfxGetApp ();

Second, the View class

Get Documentation:

GetDocument ()

Returns a pointer to the corresponding document, not a CDocument class, and does not require a type conversion.

Get main form:

CMainFrame *pmain = (CMainFrame *) AfxGetMainWnd ();

Or get the app first, get the main form from the app

Cxxxapp *papp = (Cxxxapp *) AfxGetApp ();

CMainFrame *pmain = (cmainframe*) Papp->getmainwnd ();

CMainFrame *pmain = (cmainframe*) papp->m_pmainwnd;

Get app:

Cxxxapp *papp = (Cxxxapp *) AfxGetApp ();

Third, in the main form

Get Documentation:

GetActiveDocument (); Note Type conversions

Get view:

GetActiveView (); Note Type conversions

Get app:

Cxxxapp *papp = (Cxxxapp *) AfxGetApp ();

Four, the App class

Get main form:

CMainFrame *pmain = (CMainFrame *) AfxGetMainWnd ();

CMainFrame *pmain = (cmainframe*) This->getmainwnd ();

CMainFrame *pmain = (cmainframe*) this->m_pmainwnd;

Get view:

Get the CMainFrame first, and then get the view based on CMainFrame:

Pmain->getactivedocument (); Note Type conversions

Get Documentation:

Obtain the CMainFrame first, and then obtain the document according to CMainFrame:

Pmain->getactivedocument (); Note Type conversions

V. Other classes in the program

Refer to the above method, where the app can be obtained by AfxGetApp, CMainFrame can be obtained by AfxGetMainWnd, anywhere, doc and view are the two structures that belong to CMainFrame, can be obtained by CMainFrame.

"VC + + Learning Note Four" framework class acquisition in MFC applications

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.