MFC多文档获取窗口句柄
GET App
AfxGetInstanceHandle()
AfxGetApp()
GET Frame->View->Document
SDI AfxGetMainWnd() -> GetActiveView() -> GetDocument()
MDI AfxGetMainWnd() -> MDIGetActive() -> GetActiveView() -> GetDocument()
GET Menu
CMenu *pMenu=AfxGetApp()->m_pMainWnd->GetMenu();
GET ToolBar,StatusBar
(CMainFrame *)GetParent()->m_wndToolBar;
(CMainFrame *)GetParent()->m_wndStatusBar;
CStatusBar * pStatusBa=(CStatusBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CToolBar * pToolBar=(CtoolBar*)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);
Get View from Document
GetFirstViewPosition() 和 GetNextView() 函数得到指针。
获取文档示例:
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd(); CmyDoc* pDoc = (CmyDoc*)pMainFrame->MDIGetActive()->GetActiveView()->GetDocument();