当前位置:编程学习 > VC++ >>

在VC++6.0下用MFC创建对话框及对应的类,并显示模态对话框

我先创建了dlg2对话框,接着创建了它对应的对话框类class dlg2,利用类向导添加消息响应函数之后,准备实现简单功能,但在编译时出现如下错误:E:\Microsoft Visual Studio\MyProjects\geliang\geliangDlg.cpp(175) : error C2065: 'dlg2' : undeclared identifierE:\Microsoft Visual Studio\MyProjects\geliang\geliangDlg.cpp(175) : error C2146: syntax error : missing ';' before identifier 'test'E:\Microsoft Visual Studio\MyProjects\geliang\geliangDlg.cpp(175) : error C2065: 'test' : undeclared identifierE:\Microsoft Visual Studio\MyProjects\geliang\geliangDlg.cpp(176) : error C2228: left of '.DoModal' must have class/struct/union typedlg2.cppGenerating Code...Error executing cl.exe.geliang.exe - 4 error(s), 0 warning(s) 其中消息响应函数如下:void CGeliangDlg::OnOK() { // TODO: Add extra validation here dlg2 test; int result=test.DoModal(); if (result==IDOK) {  AfxMessageBox("单击OK按钮"); }  else {  AfxMessageBox("单击cancle按钮"); } CDialog::OnOK();}请问错在哪了?为什么会出现这些错误?
答案:"我先创建了dlg2对话框,接着创建了它对应的对话框类class dlg2"这句话我不太明白什么意思,
既然楼主想要创建对话框,直接通过对话框类(CDlg?记不住)实例化一个对象,然后通过成员函数Creak创建就行了!没有必要这么复杂
其他:: error C2065: 'dlg2' : undeclared identifier   这句话说明,你的dlg2未定义!你在定义这个dlg2对象的时候,在所定义的文件中应该添加 他所属类的头文件,不然找不到dlg2的! viod dialog1::OnBnclick()
{
    (dialog2*) dlg = new dialog2;
    dlg->create(IDD_DIALOG2);
    dlg->ShowWindow(SW_SHOW);
    this->ShowWindow(SW_HIDE);
}
 

上一个:vc 不规则按钮
下一个:VC++ CreateWindow() 最后一个参数NULL错误!

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,