1、如何在视图类中获取主窗口指针
主窗口的指针保存在CWinThread::m_pMainWnd中(应用程序类的Initlnstance函数有用到),可以调用
AfxGetMainWnd获取,也可以用视图类继承的函数GetParent()获取。另外,如果要获取当前视图类对象的指针(比如要在当前视图手动添
加控件)要使用this。
2、如何在主框架类中获得视图类指针
单文档(SDI):
CMainFrame*
pMainFrame = (CMainFrame*)AfxGetMainWnd();
CYourDoc*
pDoc =
(CYourDoc*)pMainFrame->GetActiveDocument();
CYourView*
pView =
(CYourView*)pMainFrame->GetActiveView();
多文档(MDI):
CMainFrame*
pMainFrame = (CMainFrame*)AfxGetMainWnd();
CChildFrame*
pChildFrame =
(CChildFrame*)pMainFrame->GetActiveFrame();
CYourDoc*
pDoc =
(CYourDoc*)pChildFrame->GetActiveDocument();
CYourView*
pView =
(CYourView*)pChildFrame->GetActiveView();