MFC框架各部分指针获取方式
摘自:http://www.cnblogs.com/duguguiyu/archive/2007/06/22/792511.html
前人在CSDN总结的,曾经帮助过我,整理总结一下,希望也能帮助一下别人。
| 获得CWinApp | 获得CMainFrame | 获得CChildFrame | 获得CDocument | 获得CView |
在CWinApp中 |
| AfxGetMainWnd() m_pMainWnd | AfxGetMainWnd()->MDIGetActive() AfxGetMainWnd()->GetActiveFrame() | SDI:AfxGetMainWnd()->GetActiveView()->GetDocument() MDI:AfxGetMainWnd()->MDIGetActive()->GetActiveView()->GetDocument() | SDI:AfxGetMainWnd()->GetActiveView() MDI:AfxGetMainWnd()->MDIGetActive()->GetActiveView() |
在CMainFrame中 | AfxGetApp() theApp | MDIGetActive() GetActiveFrame() | SDI:GetActiveView()->GetDocument() MDI:MDIGetActive()->GetActiveView()->GetDocument() | SDI:GetActiveView() MDI:MDIGetActive()->GetActiveView() | |
在CChildFrame中 | AfxGetApp() theApp | GetParentFrame() |
| GetActiveView()->GetDocument() | GetActiveView() |
在CDocument中 | AfxGetApp() theApp | AfxGetMainWnd() | AfxGetMainWnd()->MDIGetActive() AfxGetMainWnd()->GetActiveFrame() | POSITION pos = GetFirstViewPosition();GetNextView(pos) | |
在CView中 | AfxGetApp() theApp | AfxGetMainWnd() | GetParentFrame() | GetDocument() | |
在其他类中 | AfxGetApp() | AfxGetMainWnd() | AfxGetMainWnd()->MDIGetActive() AfxGetMainWnd()->GetActiveFrame() | SDI:AfxGetMainWnd()->GetActiveView()->GetDocument() MDI:AfxGetMainWnd()->MDIGetActive()->GetActiveView()->GetDocument() | SDI:AfxGetMainWnd()->GetActiveView() MDI:AfxGetMainWnd()->MDIGetActive()->GetActiveView() |