MFC中App,Doc,MainFrame,View各指针的互相获取
2015-10-10 14:35
369 查看
MFC中App,Doc,MainFrame,View各指针的互相获取
// App中获取其它三项指针
void CSDIApp::OnApp()
{
// App
// Doc
CDocument *pDoc = ((CFrameWndEx *)m_pMainWnd)->GetActiveDocument();//成员变量CFrameWndEx m_pMainWnd
// MainFrame
CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
// View
CView *pView = ((CFrameWndEx *)m_pMainWnd)->GetActiveView();
}
// Doc中获取其它三项指针
CSDIDoc::CSDIDoc()//构造函数
{
// App
CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
// Doc
// MainFrame
// Doc的创建先于MainFrame
// View
// Doc的创建先于View
}
void CSDIDoc::OnDoc()
{
// App
// 同构造函数
// Doc
// MainFrame
CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
// View
CView *pView= (CView *)pMain->GetActiveView();
POSITION pos = GetFirstViewPosition();
pView = GetNextView(pos);
}
// MainFrame中获取其它三项指针
CMainFrame::CMainFrame()//构造函数
{
theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2005);
// App
CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
// Doc
// 构造函数里无法得到当前激活的Doc
// MainFrame
// View
// 构造函数里无法得到View指针,因为Main先于View创建。
}
void CMainFrame::OnMain()
{
// App
// 同构造函数
// Doc
CDocument *pDoc = (CDocument *)GetActiveDocument();
// MainFrame
// View
CView *pView = (CView *)GetActiveView();
}
// View中获取其它三项指针
CSDIView::CSDIView()//构造函数
{
// App
CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
// Doc
/* 无法在View的构造函数里得到Doc指针
GetDocument();实际上是返回m_pDocument
m_pDocument在OnCreate();里创建 */
//CDocument *pDoc = GetDocument();
// MainFrame
// 构造函数里无法得到MainFrame指针
// CFrameWndEx *pMain = (CFrameWndEx *)pApp->m_pMainWnd;
// View
}
void CSDIView::OnView()
{
// App
// 同构造函数
// Doc
CDocument *pDoc = GetDocument();
// MainFrame
CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
// View
}
// Dlg中获取指针
CDlg::CDlg(CWnd* pParent /*=NULL*/)//构造函数
: CDialog(CDlg::IDD, pParent)
{
// App
CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
// Doc
CDocument *pDoc = ((CFrameWndEx *)AfxGetMainWnd())->GetActiveDocument();
// MainFrame
CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
// View
CView *pView = ((CFrameWndEx *)AfxGetMainWnd())->GetActiveView();
}
参考网址:http://www.cnblogs.com/luzhiyuan/p/3936283.html
// App中获取其它三项指针
void CSDIApp::OnApp()
{
// App
// Doc
CDocument *pDoc = ((CFrameWndEx *)m_pMainWnd)->GetActiveDocument();//成员变量CFrameWndEx m_pMainWnd
// MainFrame
CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
// View
CView *pView = ((CFrameWndEx *)m_pMainWnd)->GetActiveView();
}
// Doc中获取其它三项指针
CSDIDoc::CSDIDoc()//构造函数
{
// App
CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
// Doc
// MainFrame
// Doc的创建先于MainFrame
// View
// Doc的创建先于View
}
void CSDIDoc::OnDoc()
{
// App
// 同构造函数
// Doc
// MainFrame
CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
// View
CView *pView= (CView *)pMain->GetActiveView();
POSITION pos = GetFirstViewPosition();
pView = GetNextView(pos);
}
// MainFrame中获取其它三项指针
CMainFrame::CMainFrame()//构造函数
{
theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2005);
// App
CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
// Doc
// 构造函数里无法得到当前激活的Doc
// MainFrame
// View
// 构造函数里无法得到View指针,因为Main先于View创建。
}
void CMainFrame::OnMain()
{
// App
// 同构造函数
// Doc
CDocument *pDoc = (CDocument *)GetActiveDocument();
// MainFrame
// View
CView *pView = (CView *)GetActiveView();
}
// View中获取其它三项指针
CSDIView::CSDIView()//构造函数
{
// App
CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
// Doc
/* 无法在View的构造函数里得到Doc指针
GetDocument();实际上是返回m_pDocument
m_pDocument在OnCreate();里创建 */
//CDocument *pDoc = GetDocument();
// MainFrame
// 构造函数里无法得到MainFrame指针
// CFrameWndEx *pMain = (CFrameWndEx *)pApp->m_pMainWnd;
// View
}
void CSDIView::OnView()
{
// App
// 同构造函数
// Doc
CDocument *pDoc = GetDocument();
// MainFrame
CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
// View
}
// Dlg中获取指针
CDlg::CDlg(CWnd* pParent /*=NULL*/)//构造函数
: CDialog(CDlg::IDD, pParent)
{
// App
CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
// Doc
CDocument *pDoc = ((CFrameWndEx *)AfxGetMainWnd())->GetActiveDocument();
// MainFrame
CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
// View
CView *pView = ((CFrameWndEx *)AfxGetMainWnd())->GetActiveView();
}
参考网址:http://www.cnblogs.com/luzhiyuan/p/3936283.html
相关文章推荐
- mybatis中 mapper.xml文件中,获取数组中指定的位置的数据
- unity3d中材质球纹理的滚动
- android Toast工具类
- Appendix B: Netsh Command Syntax for the Netsh Firewall Context
- Android社会化分享的实现方法
- hibernate的注解属性mappedBy详解
- android WebView java与js相互调用
- swift学习-自动引用计数(十六)
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- android log 学习
- iOS-NSUserDefaults缓存自定义对象
- Android社会化分享功能的实现步骤
- Android 主流分辨率
- 【Unity框架】Unity & MVC:如何提升游戏开发质量
- 毛玻璃效果demo
- android WebView与JS交互小结
- Swift Error fatal error: unexpectedly found nil while unwrapping an Optional value
- android TextView中超链接的事件捕捉(textview上LINK的点击事件)
- android系统栏的颜色改变和沉浸式状态栏显示
- Jenkin+Git+Gradle为Android项目搭建CI环境