50分的超级简单问题!如何在自己建立的弹出对话框中中得到CTestView的指针???

DOA hw 2002-07-31 05:11:26
谢谢!!!
...全文
10 点赞 收藏 14
写回复
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yinx 2002-07-31
获得CView类的指针:
((CFrameWnd *)(AfxGetApp()->m_pMainWnd))->GetActiveView()
获得CDocument类的指针:
((CFrameWnd *)(AfxGetApp()->m_pMainWnd))->GetActiveDocument()

或者include xxxdoc.h and include xxxview.h
回复
GoogleGeek 2002-07-31
因为在你的视图类中有
// Attributes
public:
CTestDoc* GetDocument();
的定义,在该定义中用到了文档类!
在你的对话框的实现文件中包含文件CTestView.h之前包含文档类的声明文件
如下:
....
#include "CTestDoc.h"
#include "CTestView.h"
....
--------------
OK!
回复
webber84 2002-07-31
在dialog的CPP文件中依次加入CTestDoc.h和CTestView.h,然后用下面的代码:
CFrameWnd* pMainFrame=(CFrameWnd*)AfxGetMainWnd();
CFrameWnd* pActiveFrame=pMainFrame->GetActiveFrame();
CTestView* pActiveView=(CTestView*)pActiveFrame->GetActiveView();
回复
GoogleGeek 2002-07-31
的确'GetActiveView' : is not a member of 'CWnd'
该函数实际上是:
CFrameWnd::GetActiveView
CView* GetActiveView( ) const;
这时的你需要进行强制转换!
例如:
CTestView *pView=NULL;
/Must cast the type to CMainFrame*,
CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->GetMainWnd();
pView=(CTestView *)pFrame->GetActiveView();
if(pView)
MessageBox("I have found the class CTestView!")
--------------------------------------------------------------------------
Sorry!
刚才测试了一下程序,发现有下面的问题:
无法在MDI程序中使用上面的方法获得视图类的指针!
下面是msdn上的关于该函数的说明:
This function returns NULL when called for an MDI main frame window (CMDIFrameWnd). In an MDI application, the MDI main frame window does not have a view associated with it. Instead, each individual child window (CMDIChildWnd) has one or more associated views. The active view in an MDI application can be obtained by first finding the active MDI child window and then finding the active view for that child window. The active MDI child window can be found by calling the function MDIGetActive or GetActiveFrame as demonstrated in the following:

当在一个MDI应用程序中调用该函数时,该函数的返回值是NULL,因为在MDI程序中主框架窗口并不包含相应的视图类指针。相反,每一个子框架窗口拥有相应的关联视图的指针!在MDI应用程序中可以用下面的方法获得视图类的指针:
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// Get the active MDI child window.
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();
// Get the active view attached to the active MDI child
// window.
CMyView *pView = (CMyView *) pChild->GetActiveView();



回复
DOA 2002-07-31
大侠们!好像不能解决哦。
CTestView 再Dlg中没定义。
但包含了testView.h 又会出错

'CTestDoc' : missing storage-class or type specifiers
回复
GoogleGeek 2002-07-31
的确'GetActiveView' : is not a member of 'CWnd'
该函数实际上是:
CFrameWnd::GetActiveView
CView* GetActiveView( ) const;
这时的你需要进行强制转换!
例如:
CTestView *pView=NULL;
/Must cast the type to CMainFrame*,
CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->GetMainWnd();
pView=(CTestView *)pFrame->GetActiveView();
if(pView)
MessageBox("I have found the class CTestView!");
回复
fourstone 2002-07-31
用AfxGetMainWnd()获得当前的主窗口,你将他进行一下强制转换即可,((CMainFrame *)AfxGetMainWnd())->GetActiveView()
回复
DOA 2002-07-31
救命啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
死人啦!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
回复
DOA 2002-07-31
帮帮忙啊~~~~~~~~~~~~~~~
要死人啦!!!!!!!!!!!!!!!!!!!!!!11
回复
DOA 2002-07-31
好像不对哦~~~~~

'GetActiveView' : is not a member of 'CWnd'
回复
stoneyrh 2002-07-31
AfxGetMainWnd() -> GetActiveView();
好象是这样的
找找吧
回复
DOA 2002-07-31
我的程序叫test派生了CView

高手帮帮忙吧,一句话而已嘛!!!
回复
badknife 2002-07-31
CTestView是什么?
回复
DOA 2002-07-31
为什么没人回答呢?
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告