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

DOA 2002-07-31 05:11:26
谢谢!!!
...全文
62 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
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
  • 打赏
  • 举报
回复
为什么没人回答呢?

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧