`
film
  • 浏览: 224082 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

MFC类的关系

 
阅读更多

前人在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()
理一理MFC的这几个类的关系,可以很容易明白上面的这些乱七八糟的逻辑。
App是应用域,所有的域中的东西都可以通过全局函数访问到它。
MainFrame是主框架,也基本可以用全局函数访问到。
MainFrame下是若干个ChildFrame,ChildFrame中若干个View和Document(可能不成对),ChildFrame管理着View,View和Document进行互操作。
因此整体框架就出来了,一般除了直接应用的关系都可以通过MainFrame-->Active ChildFrame-->Active View-->Document这条线进行访问,这应该叫什么来自?万能方法吧^_^。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics