MFC 获取App,Doc,MainFrame,View指针

来源:互联网 发布:电大和网络教育的区别 编辑:程序博客网 时间:2024/06/05 09:03

SDI】:

得到MainFrame的指针(pMainFrame) : 
AfxGetApp()->m_pMainWnd;  或 AfxGetMainWnd(); 或 AfxGetApp()->GetMainWnd(); 

得到View的指针(pView):
pMainFrame->GetActiveView();

得到Document类的指针(pDoc):
pMainFrame->GetActiveDocument();

MDI】:
得到ActiveFrame的指针(pChildFrm) :
((CFrameWnd*)AfxGetApp()->m_pMainWnd)->GetActiveFrame();

得到ActiveView的指针(pView):
pChildFrm->GetActiveView();

得到ActiveDocument的指针(pDoc):
pChildFrm->GetActiveDocument(); 

注:
在View中可直接通过GetDocument(); 获得Doc的指针

在Doc中可通过GetFirstViewPosition()和GetNextView()遍历所有View


0 0
原创粉丝点击