View MainFrame Document三者互相得到
从MainFrame得到Document的指针:
//从MainFrame得到Document的成员 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; // Get the active MDI child window. CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); // or CMDIChildWnd *pChild = pFrame->MDIGetActive(); // Get the active view attached to the active MDI child // window. CMSVideoMonitorView *pView = (CMSVideoMonitorView *) pChild->GetActiveView(); //Get the active Document CMSPMSDoc* pDoc = (CMSPMSDoc*)pView->GetDocument();
方法二:
CFrameWnd* pActiveFrame=GetActiveFrame(); CMSVideoMonitorView* pView=(CMSVideoMonitorView*)(pActiveFrame->GetActiveView()); 这是一种常用的方法,适合MDI和SDI(未验证)程序。
但GetActiveView()方法不能用,因为,MSDN:
This function returns NULL when called for an MDI main frame window (CMDIFrameWnd). In an MDI application, the MDI main frame window does not have a view associated with it. Instead, each individual child window (CMDIChildWnd) has one or more associated views. The active view in an MDI application can be obtained by first finding the active MDI child window and then finding the active view for that child window.
即:没有与MDI main frame绑定的View。用第一种方法正道。
浙公网安备 33010602011771号