请问:我自己定义了一个类,然后想访问view中的公共成员变量,但访问不了,怎么办?

解决方案 »

  1.   

    你的类在那里呀?若是可以, 就放在view 里好了.
      

  2.   

    include类C[XXX]View的头文件。用某种方法得到该view的指针,假如是pView;
    pView->(public data member).
      

  3.   

    1、在View的定义上面,宏定义的下面加下 CXXXView *pView;2、在构造函数中
    pView=this;3、在你要用的类中宏定义的下面
    extern CXXXView *pView;可以用了:)
      

  4.   

    #include "CMyView.h"
    #include "MainFrm.h"CMainFrame* pMain = (CMainFrame*) (AfxGetApp()->GetMainWnd());
    CMyView* pView = (CMyView*) (pMain->GetActiveView());然后就可以通过pView调用当前View的属性成员了。
      

  5.   

    不好意思,写错了,应该是这样:
    1、在你的类定义上面,宏定义的下面加下 CXXXView *pView;2、在构造函数中
    pView=this;3、在View中宏定义的下面
    extern CXXXView *pView;保证可以,准备给分吧:)
      

  6.   

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000CStyclassView * pView;//连编译都通不过呀。class CMedia  
    {
    public:
    CMedia();
    virtual ~CMedia();
    };
      

  7.   

    1、确认你的CStyclassView * pView;写在了CXXXView.cpp中
    2、确认你在构造函数中写了pView=this;例:
    #include "stdafx.h"
    #include "MfcFirst.h"#include "MfcFirstDoc.h"
    #include "MfcFirstView.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    CMfcFirstView *pView;
    CMfcFirstView::CMfcFirstView()
    {
    // TODO: add construction code here
    pView=this;
    }
      

  8.   

    先得到app的指针pApp;
    然后pApp->GetAfxMainWnd()->GetActiveView()
      

  9.   

    zswzwy(对! 我就是被封杀的☆ZSWZWY☆!) :我在自己定义的类中写:pView->m_iorange=100;
    但是它还是告诉我pView没有定义。
     
    可能是我还是不明白你的第三步怎么写,再详细点,谢谢。
      

  10.   

    是这样你一步一步来:
    1在CXXXView.cpp的宏定义下面加入CXXXView * pView;
    2在CXXXView.cpp的构造函数中加入pView=this;
    3在你要使作pView的地方,也就是你的类中(.h或.cpp)的宏定义下面加入
    extern CXXXView * pView;  如果错误提示CXXXView未定义加入XXXView.hok?
      

  11.   

    错误提示是这样的:error C2143: syntax error : missing ';'before '*'
    // Media.cpp: implementation of the CMedia class.
    //
    //////////////////////////////////////////////////////////////////////
    #include "styclassview.h"
    //#include "mainfrm.h"
    #include "stdafx.h"
    #include "styclass.h"
    #include "Media.h"#ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[]=__FILE__;
    #define new DEBUG_NEW
    #endif
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    extern CStyclassView * pView;
    CMedia::CMedia()
    {
    // CMainFrame* pMain = (CMainFrame*)(AfxGetApp()->GetMainWnd());
    //   CMyView* pView = (CMyView*) (pMain->GetActiveView());
    //extern CStyclassView * pView;
    //extern CStyclassView * pView;}CMedia::~CMedia()
    {}void CMedia::Wavlet(int scalenum, double coef[][220500])
    {}
      

  12.   

    #include "StyclassView.h"
    在错误页面的上面
      

  13.   

    请问你用什么压缩,为什么我连扩展名都看不到呀?
    你用附件再发一分到我的另一个信箱里:
    [email protected]
      

  14.   

    是RAR格式的,你到这下载吧http://count.skycn.com/download.php?id=23&url=http://sdhttp.skycn.net/down/ha_wrar31b4_zmb.exe