我用向导生成了一个单文档程序,又生成了一个基类是CWnd的类,我现在希望在这个新生成的类中得到CxxxView的指针,应当如何做?
请大家指教!
谢谢!

解决方案 »

  1.   

    POSITION PosOfView = GetFirstViewPosition();
    CXXXView* pView = (CXXXView*)GetNextView(PosOfView);
      

  2.   

    CMyView *pView = (CMyView *) pChild->GetActiveView();
      

  3.   

    你们这些方法好像都会报错啊例如
             POSITION PosOfView = GetFirstViewPosition();
    CaaaView* pView = (CaaaView*)GetNextView(PosOfView);特别是前三个错误用很多方法多报d:\documents and settings\telecom\桌面\aaa\aaaview.h(16) : error C2143: syntax error : missing ';' before '*'
    d:\documents and settings\telecom\桌面\aaa\aaaview.h(16) : error C2501: 'CaaaView::CaaaDoc' : missing storage-class or type specifiers
    d:\documents and settings\telecom\桌面\aaa\aaaview.h(16) : error C2501: 'CaaaView::GetDocument' : missing storage-class or type specifiers
    d:\documents and settings\telecom\桌面\aaa\aaaview.h(16) : warning C4183: 'GetDocument': missing return type; assumed to be a member function returning 'int'
    d:\documents and settings\telecom\桌面\aaa\bbb.cpp(23) : error C3861: 'GetFirstViewPosition': identifier not found, even with argument-dependent lookup
    d:\documents and settings\telecom\桌面\aaa\bbb.cpp(24) : error C3861: 'GetNextView': identifier not found, even with argument-dependent lookup
      

  4.   

    Seu_why(小银子)的应该不会抱错吧,其他两种我没有用过
      

  5.   

    1.在单文档应用程序的App类的.h里声明变量,但该声明在APP类定义的外部.
       extern class CXXXView* pView;    
    2.在APP类的.cpp文件的头部对全局变量pView初始化.
      CXXXView *pView=NULL;
    3.在CXXXView.cpp的构造函数里得到全局变量的实际值
      pView=this;这种方法乍一看好象有些复杂,但通过把它定义为全局变量,以后在程序的任何需要视图类指针的地方直接pView->就行了
      

  6.   

    sujinzhao407(摇风清影)谢谢你但是我不希望用全局变量bobob(PDFViewer2.0 Release拉!) 和 xuzheng318(忧郁王子) 你们两个谁可以说的详细点怎么用,可能我比较笨吧,谢谢你们了
      

  7.   

    在那个继承CWnd的类的.cpp中加入#include "stdafx.h",一定要放在第一个
      

  8.   

    在.cpp中有#include "stdafx.h",并且是在第一个我的环境是vc.net那位大虾做个例子发给我吧[email protected]谢谢
      

  9.   

    首先获得文档指针:
    AfxGetMainWnd()->GetActiveDocument()
      

  10.   

    POSITION pos=((CMainFrame*)AfxGetMainWnd())->GetActiveDocument()->GetFirstViewPosition();
    (CaaaView*)(((CMainFrame*)AfxGetMainWnd())->GetActiveDocument())->GetNextView(pos);
    我用上面两句想得到CaaaView类的指针,可是编译时总是报
    d:\documents and settings\telecom\桌面\aaa\aaaview.h(16) : error C2143: syntax error : missing ';' before '*'
    d:\documents and settings\telecom\桌面\aaa\aaaview.h(16) : error C2501: 'CaaaView::CaaaDoc' : missing storage-class or type specifiers
    d:\documents and settings\telecom\桌面\aaa\aaaview.h(16) : error C2501: 'CaaaView::GetDocument' : missing storage-class or type specifiers
    d:\documents and settings\telecom\桌面\aaa\aaaview.h(16) : warning C4183: 'GetDocument': missing return type; assumed to be a member function returning 'int'
    这几个错误把(CaaaView*)和#include "aaaView.h"去掉就没有错误了我看来就是不能把我得到的View指针转换成我需要的CaaaView指针,请问大家该怎么办?
      

  11.   

    在构造函数里把this 保存下来就好了
      

  12.   

    ((CMainframe*)AfxGetMainWnd())->GetActiveView()
      

  13.   

    非常感谢jiangsheng(蒋晟.Net)的指点,一语就使我的问题解决了,谢谢!同时也感谢大家帮忙