MFC类的关系

本文详细介绍了MFC(Microsoft Foundation Classes)中几个关键类之间的关系及其获取方式,包括CWinApp、CMainFrame、CChildFrame、CDocument和CView等,有助于理解MFC应用程序的结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前人在优快云总结的,整理总结一下,希望也能帮助一下别人。

获得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这条线进行访问,这应该叫什么来自?万能方法吧^_^。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值