Mutual acquisition of App,doc,mainframe,view pointers in MFC

Source: Internet
Author: User

First, the four-class

The order of execution is: App->doc->mainframe->view

The message response order is: View->doc->mainframe->app

1 //app to get the other three pointers2 voidCsdiapp::onapp ()3 {4     //App5     //Doc6CDocument *pdoc = ((CFrameWndEx *) m_pMainWnd)->getactivedocument ();//member variable CFrameWndEx m_pmainwnd7     //MainFrame8CFrameWndEx *pmain = (CFrameWndEx *) AfxGetMainWnd ();9     //ViewTenCView *pview = ((CFrameWndEx *) m_pMainWnd)GetActiveView (); One } A  - //doc to get the other three pointers - Csdidoc::csdidoc ()//constructor  the { -     //App -CWinAppEx *papp = (CWinAppEx *) AfxGetApp (); -     //Doc +     //MainFrame -     //Doc is created prior to mainframe +     //View A     //Doc is created prior to view at } - voidCsdidoc::ondoc () - { -     //App -     //Same constructor -     //Doc in     //MainFrame -CFrameWndEx *pmain = (CFrameWndEx *) AfxGetMainWnd (); to     //View +CView *pview= (CView *) pmain->GetActiveView ();  -POSITION pos =getfirstviewposition ();  thePView =GetNextView (POS); * } $     Panax Notoginseng three additional pointers in//mainframe - cmainframe::cmainframe ()//constructor  the { +Theapp.m_napplook = Theapp.getint (_t ("Applicationlook"), id_view_applook_vs_2005); A     //App theCWinAppEx *papp = (CWinAppEx *) AfxGetApp (); +     //Doc -     //the currently active doc is not available in the constructor $     //MainFrame $     //View -     //The view pointer cannot be obtained in the constructor because main is created before view.  - } the voidCmainframe::onmain () - {Wuyi     //App the     //Same constructor -     //Doc WuCDocument *pdoc = (CDocument *) getactivedocument (); -     //MainFrame About     //View $CView *pview = (CView *) GetActiveView (); - } -  - //view to get the other three pointers A Csdiview::csdiview ()//constructor  + { the     //App -CWinAppEx *papp = (CWinAppEx *) AfxGetApp (); $     //Doc the     /*cannot get doc pointer in view's constructor the getdocument (); actually returns m_pdocument the M_pdocument created in OnCreate ();*/ the     //CDocument *pdoc = GetDocument (); -     //MainFrame in     //mainframe pointer not available in constructor the     //CFrameWndEx *pmain = (CFrameWndEx *) papp->m_pmainwnd; the     //View About } the voidCsdiview::onview () the { the     //App +     //Same constructor -     //Doc theCDocument *pdoc =getdocument ();Bayi     //MainFrame theCFrameWndEx *pmain = (CFrameWndEx *) AfxGetMainWnd (); the     //View - } -  the //Get pointers in Dlg theCdlg::cdlg (cwnd* pparent/*=null*/)//constructor  the : CDialog (Cdlg::idd, pparent) the { -     //App theCWinAppEx *papp = (CWinAppEx *) AfxGetApp (); the     //Doc theCDocument *pdoc = ((CFrameWndEx *) AfxGetMainWnd ())getactivedocument ();94     //MainFrame theCFrameWndEx *pmain = (CFrameWndEx *) AfxGetMainWnd (); the     //View theCView *pview = ((CFrameWndEx *) AfxGetMainWnd ())GetActiveView ();98}

Mutual acquisition of App,doc,mainframe,view pointers in MFC

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.