我在C..View类中写了函数来响应“保存”菜单项,但我又需要在另一个地方也响应这函数,请问我该怎么办?因为是捕捉"ID_FILE_SAVE"消息来响应这“保存”函数的,所以无法重载它。请各位高手尽快回答,在线急等

解决方案 »

  1.   

    只要你的函数是public类型的,在其它地方取得该C...View类的指针就可以调用了吧。
      

  2.   

    对,先得到C..View对象的指针,然后就可以调用OnFileSave函数了!
      

  3.   

    那C..View是VC根据工程名起的名字,既有C..View.h又有C..View.cpp文件,我就不知该怎么才可以得到那C..View对象的指针了。这样该怎么写啊?
      

  4.   

    文档视图架构的程序,通常以文档为中心,所以取视图指针可以这样:
    CxxxView *pView;
    POSITION pos = GetDocument()->GetFirstViewPosition();
    pView = (CxxxView *)GetDocument()->GetNextView(pos);
    while(!pView->IsKindOf(RUNTIME_CLASS(CxxxView)))
    {
    pView = (CxxxView *)GetDocument()->GetNextView(pos);
    }也可以在创建视图时就保存视图指针,为后面使用。
      

  5.   

    你若是在CMainFrame里的话可以用:
    this->GetActiveView();
      

  6.   

    我提错问题了,不好意思。
    应该是这样的,在C××Doc文件中,我写了相对应于ID_FILE_SAVE的函数OnFileSave(),我现在想在MainFrame.cpp中调用这函数。请问该怎么调用它。
      

  7.   

    框架、视图、文档和其它类间的指针获取
    //从任意地方得到主框架指针
    CMainFrame* pf=(CMainFrame*)AfxGetApp()->m_pMainWnd;//得到文档指针
    CMainFrame* pf=(CMainFrame*)AfxGetApp()->m_pMainWnd;
    CMyDoc* pdoc=(CMyDoc*)pf->GetActiveDocument();//从文档取得视图指针
    POSITION pos = GetFirstViewPosition();
    if (pos != NULL)
       {
            m_pLeftView1 = (CLeftPanel1*)GetNextView(pos);
    m_pRichView1 = (CRichView1*)GetNextView(pos);
            m_pListView1 = (CListView1*)GetNextView(pos);
       }
      

  8.   

    但我在MainFrame.cpp这样用:
    CMainFrame* pf=(CMainFrame*)AfxGetApp()->m_pMainWnd;
    CPointtestDoc* pdoc=(CPointtestDoc*)pf->GetActiveDocument();
    pdoc ->OnFileSave ();
    还是编译不过啊。
      

  9.   

    这个OnFileSave ()应该是个保护函数。是用ClassVizard来增加的函数,是个受保护的函数,如果我将它改为公用函数,上面所说的问题还是没有解决。
    错误提示如下:
    F:\tuxing\PointTest\MainFrm.cpp(117) : error C2027: use of undefined type 'CPointtestDoc'
            f:\tuxing\pointtest\pointtestview.h(15) : see declaration of 'CPointtestDoc'
    F:\tuxing\PointTest\MainFrm.cpp(117) : error C2227: left of '->OnFileSave' must point to class/struct/union
      

  10.   


    在MainFrm.cpp文件前面添加#include "PointtestDoc.h"