MFC构建中,任意程序位置,获取当前活动视图、文档类

假设建立MFC工程名称为  MyTest;

//首先找到当前工程主框架

CMainFrame *pMainWnd =  (CMainFrame*)AfxGetApp()->m_pMainWnd;

//有主框架找到当前活动子框架
CMDIChildWnd *pChild =  (CMDIChildWnd *) pMainWnd->GetActiveFrame();

//由活动子框架,找到当前活动视图
CMyTestView *pView = (CMyTestView*) pChild->GetActiveView();

//当前活动是与文档通信函数GetDocument()

CMyTestDoc *pDoc=(CMyTestDoc *)pChild->GetActiveDocument();

或者

CMyTestDoc *pDoc=pView->GetDocument();

原文地址:https://www.cnblogs.com/vranger/p/3075923.html