1) 在View中获得Doc指针
CYouDoc *pDoc=GetDocument();一个视只能有一个文档。
2) 在App中获得MainFrame指针 CWinApp 中的 m_pMainWnd变量就是MainFrame的指针 也可以:
CMainFrame *pMain =(CMainFrame *)AfxGetMainWnd();
在多线程程序中,AfxGetMainWnd() 调用线程的句柄,暨当前语句所在线程的句柄,不唯一
3) 在View中获得MainFrame指针
CMainFrame *pMain=(CMainFrame*)AfxGetApp()->m_pMainWnd;
4) 获得View(已建立)指针
CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
CYouView *pView=(CYouView *)pMain->GetActiveView();
在多线程程序中,AfxGetApp()->m_pMainWnd 应用程序主线程的句柄,在一个多线程应用程序中是唯一的·
m_wndStatusBar.SetPaneText(0,dlg.GetPathName());
5) 获得当前文档指针
CYouDoc * pDoc=(CYouDoc *)pMain->GetActiveDocument();
6) 获得状态栏与工具栏指针
CStatusBar * pStatusBar=(CStatusBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CToolBar * pToolBar=(CtoolBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);
7) 如果框架中加入工具栏和状态栏变量还可以这样
(CMainFrame *)GetParent()->m_wndToolBar;
(CMainFrame *)GetParent()->m_wndStatusBar;
8) 在Mainframe获得菜单指针
CMenu *pMenu=m_pMainWnd->GetMenu();
9) 在任何类中获得应用程序类 用MFC全局函数AfxGetApp()获得。
转载于:https://www.cnblogs.com/gzy-zju-edu/articles/4014541.html