在对话框中如何获得当前的视图对象? 我有例程,可以在任何类中获得需要视图的指针,EMail 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 [email protected]如果方便的话能不能贴出来,多谢了! 下面代码可的多文档中的一个文档中 任一视指针:CTest7View* 为你想要的视指针 POSITION pos=AfxGetApp()->GetFirstDocTemplatePosition(); CDocTemplate *pTemp=AfxGetApp()->GetNextDocTemplate(pos); pos=pTemp->GetFirstDocPosition(); CDocument *pDoc=pTemp->GetNextDoc(pos); CView *pView; pos=pDoc->GetFirstViewPosition(); BOOL bFind=false; while(pos!=NULL){ pView=pDoc->GetNextView(pos); if(pView->IsKindOf(RUNTIME_CLASS(CTest7View))){ bFind=true; break; } } if(bFind) m_strDisplay=((CTest7View *)pView)->m_strDisplay; else m_strDisplay="null"; 获得mainframe的指针,调用GetActiveViewCView *pCurView=((CFrameWnd *)AfxGetMainWnd())->GetActiveView(); 大体思想是在应用类中保存这个视图的一个指针,这个指针在该视图创建是赋值,在工程中只有应用类,可以在任何类中调用,通过AfxGetApp便可获得应用类指针,在获得该视图的指针.思想是这样,实现时有一些细节,给你个例程看看比较负责,实际也是真正的帮助! 先多谢各位,现在还有一点问题。为了在CNodePropertyDlg对话框里使用我需要的CFlowDefineView视图对象,我在NodePropertyDlg.cpp文件里引用了#include "FlowDefineView.h",但是编译出现了7个Error,把#inlcude那句去掉就没问题,当然我不希望,因为我需要使用CFlowDefineView* pView对象。错误如下,希望大家再次帮忙。--------------------Configuration: FlowDefine - Win32 Debug--------------------Compiling...NodePropertyDlg.cppc:\gzm\flowdefine\flowdefineview.h(20) : error C2143: syntax error : missing ';' before '*'c:\gzm\flowdefine\flowdefineview.h(20) : error C2501: 'CFlowDefineDoc' : missing storage-class or type specifiersc:\gzm\flowdefine\flowdefineview.h(20) : error C2501: 'GetDocument' : missing storage-class or type specifiersc:\gzm\flowdefine\flowdefineview.h(22) : error C2146: syntax error : missing ';' before identifier 'm_AddFlow'c:\gzm\flowdefine\flowdefineview.h(22) : error C2501: 'CAddFlow' : missing storage-class or type specifiersc:\gzm\flowdefine\flowdefineview.h(22) : error C2501: 'm_AddFlow' : missing storage-class or type specifiersc:\gzm\flowdefine\flowdefineview.h(30) : error C2061: syntax error : identifier 'CLink'Error executing cl.exe.Creating browse info file...FlowDefine.exe - 7 error(s), 0 warning(s) 在flowdefineview.h 文件中包含各个类('CFlowDefineDoc' 'CAddFlow' 'CLink')的头文件 为什么要这样呢?我不#include "FlowDefineView.h"编译成功啊,FlowDefineView.h中也不用包含那些头文件。 在flowdefineview.h 中加了头文件还是不行,编译说有重复定义错误。--------------------Configuration: FlowDefine - Win32 Debug--------------------Compiling...NodePropertyDlg.cppc:\gzm\flowdefine\node.h(15) : error C2011: 'CNode' : 'class' type redefinitionc:\gzm\flowdefine\flowdefineview.h(24) : error C2143: syntax error : missing ';' before '*'c:\gzm\flowdefine\flowdefineview.h(24) : error C2501: 'CFlowDefineDoc' : missing storage-class or type specifiersc:\gzm\flowdefine\flowdefineview.h(24) : error C2501: 'GetDocument' : missing storage-class or type specifiersGenerating Code...Compiling...FlowDefine.cppc:\gzm\flowdefine\node.h(15) : error C2011: 'CNode' : 'class' type redefinitionc:\gzm\flowdefine\link.h(15) : error C2011: 'CLink' : 'class' type redefinitionc:\gzm\flowdefine\addflow.h(19) : error C2011: 'CAddFlow' : 'class' type redefinitionGenerating Code...Compiling...FlowDefineDoc.cppc:\gzm\flowdefine\node.h(15) : error C2011: 'CNode' : 'class' type redefinitionc:\gzm\flowdefine\link.h(15) : error C2011: 'CLink' : 'class' type redefinitionc:\gzm\flowdefine\addflow.h(19) : error C2011: 'CAddFlow' : 'class' type redefinitionGenerating Code...Compiling...FlowDefineView.cppc:\gzm\flowdefine\node.h(15) : error C2011: 'CNode' : 'class' type redefinitionc:\gzm\flowdefine\link.h(15) : error C2011: 'CLink' : 'class' type redefinitionc:\gzm\flowdefine\addflow.h(19) : error C2011: 'CAddFlow' : 'class' type redefinitionGenerating Code...Error executing cl.exe.Creating browse info file...FlowDefine.exe - 13 error(s), 0 warning(s) 应该有各类层次:1、自定义类2、视类3、文档类在低层中须包含高层时,用include 在高层中须包含低层时,在.h文件中用 类声明 ,在.cpp文件中用 include ,如在视类中包含文档: .h文件中 class CXXDoc; .cpp文件中 #include “XXDoc.h" 强行修改对话框的构造函数!把CView *pView(也就是this)传给对话框! 关于对话框之间的传值问题,新手提问,谢谢 MFC如何实现选择程序界面 求教 如何获取硬盘的序列号 调用别的类的方法,得不到该方法的句柄,请高手帮忙 请大侠们帮忙解决一个技术问题 .dat,.cs类型数据文件,用什么工具打开.. 散分:请推荐一本既可以作教材又可以参考的好的VC书,谢谢! 一个opengl的问题!请求各位帮忙 哪里有注册表的书下载? 哪里有显示图象文件的源码 请问计算机硕士,C++(精通)开发在上海能拿多少月薪? 35分求购:输入输出流编写的读数据文件入变量例子
如果方便的话能不能贴出来,多谢了!
CTest7View* 为你想要的视指针 POSITION pos=AfxGetApp()->GetFirstDocTemplatePosition();
CDocTemplate *pTemp=AfxGetApp()->GetNextDocTemplate(pos);
pos=pTemp->GetFirstDocPosition();
CDocument *pDoc=pTemp->GetNextDoc(pos);
CView *pView;
pos=pDoc->GetFirstViewPosition(); BOOL bFind=false;
while(pos!=NULL){
pView=pDoc->GetNextView(pos);
if(pView->IsKindOf(RUNTIME_CLASS(CTest7View))){
bFind=true;
break;
}
} if(bFind) m_strDisplay=((CTest7View *)pView)->m_strDisplay;
else m_strDisplay="null";
CView *pCurView=((CFrameWnd *)AfxGetMainWnd())->GetActiveView();
在工程中只有应用类,可以在任何类中调用,通过AfxGetApp便可获得应用类指针,在获得该视图的指针.
思想是这样,实现时有一些细节,给你个例程看看比较负责,实际也是真正的帮助!
错误如下,希望大家再次帮忙。
--------------------Configuration: FlowDefine - Win32 Debug--------------------
Compiling...
NodePropertyDlg.cpp
c:\gzm\flowdefine\flowdefineview.h(20) : error C2143: syntax error : missing ';' before '*'
c:\gzm\flowdefine\flowdefineview.h(20) : error C2501: 'CFlowDefineDoc' : missing storage-class or type specifiers
c:\gzm\flowdefine\flowdefineview.h(20) : error C2501: 'GetDocument' : missing storage-class or type specifiers
c:\gzm\flowdefine\flowdefineview.h(22) : error C2146: syntax error : missing ';' before identifier 'm_AddFlow'
c:\gzm\flowdefine\flowdefineview.h(22) : error C2501: 'CAddFlow' : missing storage-class or type specifiers
c:\gzm\flowdefine\flowdefineview.h(22) : error C2501: 'm_AddFlow' : missing storage-class or type specifiers
c:\gzm\flowdefine\flowdefineview.h(30) : error C2061: syntax error : identifier 'CLink'
Error executing cl.exe.
Creating browse info file...FlowDefine.exe - 7 error(s), 0 warning(s)
--------------------Configuration: FlowDefine - Win32 Debug--------------------
Compiling...
NodePropertyDlg.cpp
c:\gzm\flowdefine\node.h(15) : error C2011: 'CNode' : 'class' type redefinition
c:\gzm\flowdefine\flowdefineview.h(24) : error C2143: syntax error : missing ';' before '*'
c:\gzm\flowdefine\flowdefineview.h(24) : error C2501: 'CFlowDefineDoc' : missing storage-class or type specifiers
c:\gzm\flowdefine\flowdefineview.h(24) : error C2501: 'GetDocument' : missing storage-class or type specifiers
Generating Code...
Compiling...
FlowDefine.cpp
c:\gzm\flowdefine\node.h(15) : error C2011: 'CNode' : 'class' type redefinition
c:\gzm\flowdefine\link.h(15) : error C2011: 'CLink' : 'class' type redefinition
c:\gzm\flowdefine\addflow.h(19) : error C2011: 'CAddFlow' : 'class' type redefinition
Generating Code...
Compiling...
FlowDefineDoc.cpp
c:\gzm\flowdefine\node.h(15) : error C2011: 'CNode' : 'class' type redefinition
c:\gzm\flowdefine\link.h(15) : error C2011: 'CLink' : 'class' type redefinition
c:\gzm\flowdefine\addflow.h(19) : error C2011: 'CAddFlow' : 'class' type redefinition
Generating Code...
Compiling...
FlowDefineView.cpp
c:\gzm\flowdefine\node.h(15) : error C2011: 'CNode' : 'class' type redefinition
c:\gzm\flowdefine\link.h(15) : error C2011: 'CLink' : 'class' type redefinition
c:\gzm\flowdefine\addflow.h(19) : error C2011: 'CAddFlow' : 'class' type redefinition
Generating Code...
Error executing cl.exe.
Creating browse info file...FlowDefine.exe - 13 error(s), 0 warning(s)
1、自定义类
2、视类
3、文档类在低层中须包含高层时,用include
在高层中须包含低层时,在.h文件中用 类声明 ,在.cpp文件中用 include ,
如在视类中包含文档: .h文件中 class CXXDoc;
.cpp文件中 #include “XXDoc.h"