How to get variable CMainFrame in the CView

// global function AfxGetApp can get CWinApp application class pointer 
// AfxGetApp () -> m_pMainWnd frame window pointer 
// in the frame window: CFrameWnd :: GetActiveDocument get the current active document pointer 
// in the frame window: CFrameWnd :: GetActiveView to give the currently active view pointer 
// in view: CView :: GetDocument give the corresponding file pointer 
// in the document: CDocument :: GetFirstViewPosition, CDocument :: GetNextView used to traverse and view all associated with the document. 
// in the document: CDocument :: GetDocTemplate get the document template pointers 
// in a multiple document interface: CMDIFrameWnd :: MDIGetActive get the currently active MDI child window


// with the following statement:
the CMainFrame * pFrame = (the CMainFrame *) (AfxGetApp ( ) -> m_pMainWnd);
// you can get custom member of the CMainFrame.
// Note that can not use AfxGetApp () -> GetMainWnd () or AfxGetMainWnd (), they can only obtain a pointer to the parent class CMainFrame, and may be a temporary pointer to an object, that is, the use of CMainFrame * mandatory return results, but also in obtaining access CMainFrame custom members.
// By the way, why not use the MFC Document / View framework, some attributes are defined in the Document,
// this is easy to access in the view. (With CView :: GetDocument ()).

Guess you like

Origin blog.csdn.net/thanklife/article/details/90374573