我想在一个单文档窗口有一个按钮,单击该按钮时弹出信息框显示“欢迎进入VC++世界”
我的方法如下:
1、建立一个项目名为sp2.用的是mfc appwizard(exe),选择创建一个空的单文档
2、单击“insert”菜单中的“resourse“命令,在弹出的对话框中选择插入的资源是dialog(名为IDD_DIaLOG1)
3、把生成的对话框中的“ok”和"cancel"按钮删除。
4、添加一个按钮(名字是BUTTON1),然后用类向导建立一个名为CMyDlg的类。在objectid中选择IDC_BUTTON1,在message中选择BN_CLICKED,对该消息编写代码为:
MessageBox("欢迎进入VC++世界")
5、然后我在,Csp2app类中的Initinstance过程的return TRUE前添加代码如下
    CMyDlg  dlg;
    dlg.DoModal();
6、在mainfrm.cpp和sp2.cpp中添加#include "MyDlg.h"
7、编译不能通过,出现以下信息。
C:\vc\sp2\sp2.cpp(95) : error C2065: 'CMyDlg' : undeclared identifier
C:\vc\sp2\sp2.cpp(95) : error C2146: syntax error : missing ';' before identifier 'dlg'
C:\vc\sp2\sp2.cpp(95) : error C2065: 'dlg' : undeclared identifier
C:\vc\sp2\sp2.cpp(96) : error C2228: left of '.DoModal' must have class/struct/union type
Error executing cl.exe.请各位帮助解决一下。

解决方案 »

  1.   

    6、在mainfrm.cpp和sp2.cpp中添加#include "MyDlg.h"
    只在sp2.cpp 的上面加#include "MyDlg.h"
    就可以了.
      

  2.   

    你的类名不会不是'CMyDlg' 吧
      

  3.   

    我很严肃的告诉你,你的操作没有错误,错误在于#include "stdafx.h"
    #include "MyDlg.h";  //请把这个加在#include "stdafx.h"后面
      

  4.   

    对,因为加在#include "stdafx.h"上面的任何头文件都不会被定位.
      

  5.   

    在需要用到的地方 cpp文件中加上#include "MyDlg.h"
      

  6.   

    谢谢各位的帮助
    我在#include "stdafx.h"后加入
       #include "MyDlg.h";  
    解决了以上问题。但新问题出现了,出现以下提示(其中'IDD_DIALOG1' 是我创建的一个对话框名)
    MainFrm.cpp
    c:\vc\sp2\mydlg.h(21) : error C2065: 'IDD_DIALOG1' : undeclared identifier
    c:\vc\sp2\mydlg.h(21) : error C2057: expected constant expression
    sp2.cpp
    c:\vc\sp2\mydlg.h(21) : error C2065: 'IDD_DIALOG1' : undeclared identifier
    c:\vc\sp2\mydlg.h(21) : error C2057: expected constant expression
    Generating Code...
    Error executing cl.exe.sp2.exe - 4 error(s怎么解决以上问题
      

  7.   

    不知是不是你笔误,你在前面说‘IDD_DIaLOG1’,现在变成'IDD_DIALOG1'