对话框调用的 对象定义问题

来源:百度知道 编辑:UC知道 时间:2024/09/12 16:59:22
我使用了对话框中的一个按钮调用另一个对话框,在这个按钮生成的函数中定义了该对话框的对象,如下:
void CSim203Dlg::OnStretchButton()
{
// TODO: Add your control notification handler code here
CStretchscopeDlg dlg2;

}
在CPP开头也加了对话框的头文件:#include "StretchscopeDlg.h"
编译出现了3个错误
Compiling...
Sim203Dlg.cpp
E:\资料\2\Sim203\Sim203Dlg.cpp(221) : error C2065: 'CStretchscopeDlg' : undeclared identifier
E:\资料\2\Sim203\Sim203Dlg.cpp(221) : error C2146: syntax error : missing ';' before identifier 'dlg2'
E:\资料\2\Sim203\Sim203Dlg.cpp(221) : error C2065: 'dlg2' : undeclared identifier
Error executing cl.exe.

Sim203Dlg.obj - 3 error(s), 0 warning(s)
我不知道是不是我定义的位置有问题,麻烦高手解释一下,谢谢!!
如果把Debug文件删除的话编译就剩一个错误了:
Compiling...
Sim203Dlg.cpp
e:\资料\2\sim203\sim203dlg.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/Sim203

试一下把 #include "StretchscopeDlg.h" 放到 "Sim203Dlg.h" 开头。
不行的话把project 里的Debug 和 Release 文件夹都删除,然后重新build.

另外你还得在 OnStretchButton() 里加上 "dlg2.DoModal();"

#include "StretchscopeDlg.h" 在整个工程的其他头文件中应该也出现了这句话,可能导致了重复定义。你可以换成这个
extern class CStretchscopeDlg;