MFC框架各部分指针获取方式

来源:互联网 发布:unity3d灯光教程 编辑:程序博客网 时间:2024/05/20 17:38

 

 

获得CWinApp

获得CMainFrame

获得CChildFrame

(很明显只有在MDI情况下才有这种情况)

获得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() 

App是应用域,所有的域中的东西都可以通过全局函数访问到它。MainFrame是主框架,也基本可以用全局函数访问到。MainFrame下是若干个ChildFrame,ChildFrame中若干个View和Document(可能不成对),ChildFrame管理着View,View和Document进行互操作。因此整体框架就出来了,一般除了直接应用的关系都可以通过MainFrame-->Active ChildFrame-->Active View-->Document这条线进行访问

getactiveview

目录

  1. 说明
  2. 返回值
  3. 备注
  4. 实例
展开
CFrameWnd::GetActiveView

说明

调用该成员函数获取指向活动视图(如果有)附加到框架窗口(CFrameWnd)。
CView* GetActiveView( ) const;

返回值

对当前 CView的指针。 如果没有当前视图中,返回 NULL

备注

此函数返回 NULL,在调用对MDI主框架窗口(CMDIFrameWnd)。 在MDI应用程序中,MDI主框架窗口没有一个关联的视图。 相反,每个单独的子窗口(CMDIChildWnd)具有一个或多个关联的视图。 在MDI应用程序的活动视图可以通过首先查找活动的MDI子窗口然后找到该子窗口的事件视图获取。 活动MDI子窗口可以通过调用函数来找到MDIGetActiveGetActiveFrame

实例

<p>CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->GetMainWnd();
// 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.
CMyView *pView = (CMyView*)pChild->GetActiveView();
</p>

 

原创粉丝点击