用mfc的单文档生成,添加了一个自定义类Dialog
用于主窗口菜单弹出的对话框。
Dialog.h在CResultsManagerView.h中有被包含,
并有一个Dialog实例dlg。在Dialog.cpp中有一个处理确认控件消息的函数:…………void Dialog::OnOK()
{
// TODO: Add extra validation here

CResultsManagerView::OnInsert();//此句为我添加的

CDialog::OnOK();
}…………想调用CResultsManagerView类(ResultsManager为自己取的工程名)中的
OnInsert()函数(一个用向导生成的主窗口菜单命令消息响应函数,
在头文件中声明为public),结果不能调用,编译报错:
G:\编程\pSave\vc\ResultsManager\Dialog.cpp(51) :error C2653:
 'CResultsManagerView' : is not a class or namespace nameG:\编程\pSave\vc\ResultsManager\Dialog.cpp(51) : error C2065:
 'OnInsert' : undeclared identifier小弟我想尽办法,实在没辙,望各位大哥不吝指点一二。
不胜感激。

解决方案 »

  1.   

    你可以通过PostMessage( WM_COMMAND, ID_INSERTMARK, 0 );试试
      

  2.   

    在Dialog.cpp里包含了CResultsManagerView.h吗
      

  3.   

    在Dialog.cpp里包含了CResultsManagerView.h后出现
    g:\编程\psave\vc\resultsmanager\dialog.h(9) : fatal error C1083: Cannot open include file: 'CResultsManagerView.h': No such file or directory
      

  4.   

    要定以一个CResultsManagerView对象,才好调用吧!
      

  5.   

    把你的这句:
         CResultsManagerView::OnInsert();
    改为
                   OnInsert();
      试试。
      

  6.   

    哈哈,你不能用 类名::方法()来调用一般的函数,只有静态函数可以这样用。你必须先声明并实例化一个类对象,通过  对象.方法名 来调用,先自已看看吧,在类定义里面是不是忘了加上static的关键字啊!
      

  7.   

    在Dialog.cpp里包含了CResultsManagerView.h后出现,哈哈,一般而言,VC中产生的文件与其类名相似,但少一个开头的C字,所以,你应该包括的是ResultsManagerView.h,而不是CResultsManagerView.h,现在再试试,应该不会有总是啦!
      

  8.   

    CResultsManagerView::OnInsert();
    这样调用除非OnInsert是static的函数才可以。你应该设法在Dialog中得到要处理的CResultsManagerView对象指针(比如通过GetActiveView()),然后调用该函数。sans(sans) (  ) 的方法应该也是可以的,如果你的对象可以响应COMMAND消息的话。
      

  9.   

    别吓我ResultsManagerView.h加入dialog.cpp后出现20多条根本不对头的错误。
    如果CResultsManagerView::OnInsert()是这样
    protected:
    //{{AFX_MSG(CResultsManagerView)
    afx_msg void OnInsert();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    的保护声明怎么在dialog中调用
      

  10.   

    protected的话,用消息应该可以
    还有别的方法么??
      

  11.   

    帮帮忙,怎么对付protected的函数(跨类调用)。
    或者将protected 型改成 public型的方法也可以。
      

  12.   

    #include "CResultsManagerView.h"CResultsManagerView pview;
    pview.OnInsert();
      

  13.   

    我记得vc自己创建的类的文件名不是以CXXXX开头的
    你看看,再:#include "ResultsManagerView.h"
      

  14.   

    #include "CResultsManagerView.h"
    #include "ResultsManagerView.h"
    都试过了,不行,会有很多错误用象sans(sans) (  ) 的方法已经可以办到了
    不过要用SendMessage(WM_COMMAND,IDM_INSERTMARK,0);才行我相知到有没有不用发消息的方法
      

  15.   

    OnInsert是静态函数吗?如果不是请用实例名限定OnInsert
      

  16.   

    Dialog.h在CResultsManagerView.h中有被包含
    ResultsManagerView.h在CDialog中包含,没有预防措施肯定要出问题三1、如果你的Dialog类是CDialog请改正。
    2、解决的方法有两种:
       (1) 在你的Dialog类(姑且叫做CMyDialog)头部添加:
            #ifdef MYDIALOG
            #define MYDIALOG
            在你的Dialog尾部添加:
            #endif
            只要能使两个类不互相包容就行。
            然后可以通过AfxGetMainWnd,AfxGetActiveView等函数得到你当前的View类指针,强制转化为CResultsManagerView,然后就随便你怎么调用你的函数了(当然是你的PUBLIC函数)
        (2) 就是往你的CView类发送消息了。这个很简单,去看一下怎么处理自定义消息的资料就明白了。
         祝好运。
      

  17.   

    首先你必须添加头文件
    #include "ResultsManagerView.h"然后定义一个CResultsManagerView的对象
    CResultsManagerView *pview;
    如果你的OnInsert()函数是保护(protected)的,可以在CResultsManagerView
    中添加一个public型的函数
    void CResultsManagerView::CallInsertmake()
    {
         OnInsert
    };最好调用函数OnInsert()或者CallInsertmake()OK!
      

  18.   

    我建议你用消息发送吧
    在生成对话框实例dlg时,把CResultsManagerView指针传进去,然后调用
    SendMessage函数,而不是PostMessage,因为第一个函数调用完后主进程
    把该消息压入消息堆栈中并放置第一位,效果相当于你在dlg.OnOk()中调用
    OnInsert函数。
      

  19.   

    这种方法应该可以!
    1,在对话框中定义的.h中定义
    CResultsManagerView *m_View;
    2,在对话框中定义的.cpp中的构造器中增加
    m_View = (CResultsManagerView  *)pParent;
    3,在对话框中定义的.cpp中OnOk()中增加
    m_View->OnInsert();
    4,在CResultsManagerView 的.cpp文件中增加
      MyDialog dlg(this);
      dlg.DoModal();OK!
    祝你好运