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