用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小弟我想尽办法,实在没辙,望各位大哥不吝指点一二。
不胜感激。
用于主窗口菜单弹出的对话框。
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小弟我想尽办法,实在没辙,望各位大哥不吝指点一二。
不胜感激。
解决方案 »
- MFC 菜单灰色 问题
- getMessage 为什么return -1就能退出
- 游戏中的验证码识别,需要哪些知识才能识别出呢?
- VC画会动直线的问题
- 来者有分:我在Dlg中建了Toolbar,同时有scrollbar,当scrollbar滚动时,整个界面都移动了,包括Toolbar。我希望Toolbar能固定,不随scrollbar移动
- 求教关于CString中FindOneOf的问题.
- 高分请教关于USBKEY、GINA(续)
- 为什么我调用了Invalidate()、UpdateWindow(),之后,OnPaint不被调用。急!!
- 我的新建了一个程序,并自定义了一个扩展名,如果用户双击改扩展名将会调用我的程序来打开。
- PE文件的一个很困惑问题?????
- 在win32程序如何使用ADO??
- 一个菜菜的网络通讯问题,巨分
g:\编程\psave\vc\resultsmanager\dialog.h(9) : fatal error C1083: Cannot open include file: 'CResultsManagerView.h': No such file or directory
CResultsManagerView::OnInsert();
改为
OnInsert();
试试。
这样调用除非OnInsert是static的函数才可以。你应该设法在Dialog中得到要处理的CResultsManagerView对象指针(比如通过GetActiveView()),然后调用该函数。sans(sans) ( ) 的方法应该也是可以的,如果你的对象可以响应COMMAND消息的话。
如果CResultsManagerView::OnInsert()是这样
protected:
//{{AFX_MSG(CResultsManagerView)
afx_msg void OnInsert();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
的保护声明怎么在dialog中调用
还有别的方法么??
或者将protected 型改成 public型的方法也可以。
pview.OnInsert();
你看看,再:#include "ResultsManagerView.h"
#include "ResultsManagerView.h"
都试过了,不行,会有很多错误用象sans(sans) ( ) 的方法已经可以办到了
不过要用SendMessage(WM_COMMAND,IDM_INSERTMARK,0);才行我相知到有没有不用发消息的方法
ResultsManagerView.h在CDialog中包含,没有预防措施肯定要出问题三1、如果你的Dialog类是CDialog请改正。
2、解决的方法有两种:
(1) 在你的Dialog类(姑且叫做CMyDialog)头部添加:
#ifdef MYDIALOG
#define MYDIALOG
在你的Dialog尾部添加:
#endif
只要能使两个类不互相包容就行。
然后可以通过AfxGetMainWnd,AfxGetActiveView等函数得到你当前的View类指针,强制转化为CResultsManagerView,然后就随便你怎么调用你的函数了(当然是你的PUBLIC函数)
(2) 就是往你的CView类发送消息了。这个很简单,去看一下怎么处理自定义消息的资料就明白了。
祝好运。
#include "ResultsManagerView.h"然后定义一个CResultsManagerView的对象
CResultsManagerView *pview;
如果你的OnInsert()函数是保护(protected)的,可以在CResultsManagerView
中添加一个public型的函数
void CResultsManagerView::CallInsertmake()
{
OnInsert
};最好调用函数OnInsert()或者CallInsertmake()OK!
在生成对话框实例dlg时,把CResultsManagerView指针传进去,然后调用
SendMessage函数,而不是PostMessage,因为第一个函数调用完后主进程
把该消息压入消息堆栈中并放置第一位,效果相当于你在dlg.OnOk()中调用
OnInsert函数。
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!
祝你好运