<转>文档视图指针互获
来源:互联网 发布:自动发卡程序源码 编辑:程序博客网 时间:2024/05/20 11:21
1) 在View中获得Doc指针 CYouSDIDoc *pDoc=GetDocument();一个视只能有一个文档。
2) 在App中获得MainFrame指针
CWinApp 中的 m_pMainWnd变量就是MainFrame的指针
也可以: CMainFrame *pMain =(CMainFrame *)AfxGetMainWnd();
3) 在View中获得MainFrame指针 CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
4) 获得View(已建立)指针 CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
CyouView *pView=(CyouView *)pMain->GetActiveView();
5) 获得当前文档指针 CDocument * pCurrentDoc =(CFrameWnd *)m_pMainWnd->GetActiveDocument();
6) 获得状态栏与工具栏指针 CStatusBar * pStatusBar=(CStatusBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CToolBar * pToolBar=(CtoolBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);
7) 如果框架中加入工具栏和状态栏变量还可以这样
(CMainFrame *)GetParent()->m_wndToolBar;
(CMainFrame *)GetParent()->m_wndStatusBar;
8) 在Mainframe获得菜单指针 CMenu *pMenu=m_pMainWnd->GetMenu();
9) 在任何类中获得应用程序类
用MFC全局函数AfxGetApp()获得。
10) 从文档类取得视图类的指针
我是从http://download.cqcnc.com/soft/program/article/vc/vc405.html学到的,
从文档获得视图类指针目的一般为了控制同一文档的多个视图的定位问题,我的体会
特别是文字处理CEditView当产生多个视图类时,这个功能是非常需要的。
CDocument类提供了两个函数用于视图类的定位:
GetFirstViewPosition()和GetNextView()
virtual POSITION GetFirstViewPosition() const;
virtual CView* GetNextView(POSITION& rPosition) const;
on、CWinApp::GetNextDocTemplate来遍历所有文档模板文档调用CDocument::GetFirstViewPosition,CDocument::GetNextView来遍历所有和文档关联的视图;调用CDocument:: GetDocTemplate 获取文档模板指针文档模板调用CDocTemplate::GetFirstDocPosition、CDocTemplate::GetNextDoc来遍历所有对应文档视图调用CView::GetDocument 得到对应的文档指针;调用CView::GetParentFrame 获取框架窗口文档框架窗口调用CFrameWnd::GetActiveView 获取当前得到当前活动视图指针;调用CFrameWnd::GetActiveDocument 获取附加到当前视图的文档指针MDI 框架窗口调用CMDIFrameWnd::MDIGetActive 获取当前活动的MDI子窗口(CMDIChildWnd)
综合应用上表中的函数,写一段代码,它完成遍历文档模板、文档和视图的功能:
CMyApp *pMyApp = (CMyApp*)AfxGetApp(); //得到应用程序指针
POSITION p = pMyApp->GetFirstDocTemplatePosition();//得到第1个文档模板
while (p != NULL) //遍历文档模板
{
CDocTemplate *pDocTemplate = pMyApp->GetNextDocTemplate(p);
POSITION p1 = pDocTemplate->GetFirstDocPosition();//得到文档模板对应的第1个文档
while (p1 != NULL) //遍历文档模板对应的文档
{
CDocument *pDocument = pDocTemplate->GetNextDoc(p1);
POSITION p2 = pDocument->GetFirstViewPosition(); //得到文档对应的第1个视图
while (p2 != NULL) //遍历文档对应的视图
{
CView *pView = pDocument->GetNextView(p2);
}
}
}
2) 在App中获得MainFrame指针
CWinApp 中的 m_pMainWnd变量就是MainFrame的指针
也可以: CMainFrame *pMain =(CMainFrame *)AfxGetMainWnd();
3) 在View中获得MainFrame指针 CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
4) 获得View(已建立)指针 CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
CyouView *pView=(CyouView *)pMain->GetActiveView();
5) 获得当前文档指针 CDocument * pCurrentDoc =(CFrameWnd *)m_pMainWnd->GetActiveDocument();
6) 获得状态栏与工具栏指针 CStatusBar * pStatusBar=(CStatusBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CToolBar * pToolBar=(CtoolBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);
7) 如果框架中加入工具栏和状态栏变量还可以这样
(CMainFrame *)GetParent()->m_wndToolBar;
(CMainFrame *)GetParent()->m_wndStatusBar;
8) 在Mainframe获得菜单指针 CMenu *pMenu=m_pMainWnd->GetMenu();
9) 在任何类中获得应用程序类
用MFC全局函数AfxGetApp()获得。
10) 从文档类取得视图类的指针
我是从http://download.cqcnc.com/soft/program/article/vc/vc405.html学到的,
从文档获得视图类指针目的一般为了控制同一文档的多个视图的定位问题,我的体会
特别是文字处理CEditView当产生多个视图类时,这个功能是非常需要的。
CDocument类提供了两个函数用于视图类的定位:
GetFirstViewPosition()和GetNextView()
virtual POSITION GetFirstViewPosition() const;
virtual CView* GetNextView(POSITION& rPosition) const;
综合应用上表中的函数,写一段代码,它完成遍历文档模板、文档和视图的功能:
CMyApp *pMyApp = (CMyApp*)AfxGetApp(); //得到应用程序指针
POSITION p = pMyApp->GetFirstDocTemplatePosit
while (p != NULL) //遍历文档模板
{
CDocTemplate *pDocTemplate = pMyApp->GetNextDocTemplate(p);
POSITION p1 = pDocTemplate->GetFirstDocPosition();//得到文档模板对应的第1个文档
while (p1 != NULL) //遍历文档模板对应的文档
{
CDocument *pDocument = pDocTemplate->GetNextDoc(p1);
POSITION p2 = pDocument->GetFirstViewPosition(); //得到文档对应的第1个视图
while (p2 != NULL) //遍历文档对应的视图
{
CView *pView = pDocument->GetNextView(p2);
}
}
}
- <转>文档视图指针互获
- 获取文档视图框架指针
- 单文档多视图获取视图指针
- VC多文档程序文档,视图、文档指针遍历问题
- 获得指针(文档、视图、框架)
- 获得指针(文档、视图、框架)
- 如何获得指针 在文档视图中
- 获得指针(文档、视图、框架)
- 获得指针(文档、视图、框架)
- 从文档类获取视图类指针
- MFC获取框架,视图,文档指针
- 单文档视图中如何获得视图指针
- 常用获得文档类和视图类指针的方法
- 从文档类取得视图类的指针
- VC: 如何获得当前程序的视图,文档指针
- VC:如何获得当前程序的视图,文档指针
- MFC获取文档 视图 程序 框架类的指针
- MFC中获取【文档】【视图】【框架】【应用程序】指针的方法
- iOS ScrollView自动滚动的代码
- 组合数
- 110601 How many Fibs
- 大内核锁将何去何从
- ResourceDictionary.Source 属性
- <转>文档视图指针互获
- MFC笔记13.11.15
- WinForm程序中未处理异常的解决方法
- PHP RSS订阅类
- 微店网迎来电商春天,共享3.2万亿市场盛宴
- struts2 使用注解 导出excel
- 设备独立像素(density)与像素(pixel)
- C++中头文件相互包含的几点问题
- 坑:ADO连数据库服务器地址要加端口号