错误代码的链接为:http://www.clsoft.net/temp/hk/myprojects.rar这是我的代码:
BOOL dlg::OnInitDialog()
{
CDialog::OnInitDialog();MessageBox("主窗体被打开!");错误提示为:
}
--------------------Configuration: myprojects - Win32 Debug--------------------
Compiling...
dlg.cpp
F:\VC练习\myprojects\dlg.cpp(36) : error C2509: 'OnInitDialog' : member function not declared in 'dlg'
        f:\vc练习\myprojects\dlg.h(13) : see declaration of 'dlg'
Error executing cl.exe.myprojects.exe - 1 error(s), 0 warning(s)

解决方案 »

  1.   

    你的函数直接在dlg.cpp中加入,但在dlg.h中没有声明。可以通过ClassWizard加入,或者在dlg.h中相应位置加入函数声明:
    // Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(dlg)
    virtual BOOL OnInitDialog();//加入该行即可
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
      

  2.   

    楼上的说得对,不过你的函数还应该作点改动,主要是要有个返回值,
    我的建议如下:
    BOOL dlg::OnInitDialog()
    {
    MessageBox("主窗体被打开!");
    return CDialog::OnInitDialog();
    }
      

  3.   

    jnxulei大侠,我加上了,但还是出错!!
    --------------------Configuration: myprojects - Win32 Debug--------------------
    Compiling...
    dlg.cpp
    Generating Code...
    Skipping... (no relevant changes detected)
    myprojectsDlg.cpp
    F:\VC练习\myprojects\dlg.cpp(40) : error C4716: 'dlg::OnInitDialog' : must return a value
    Error executing cl.exe.myprojects.exe - 1 error(s), 0 warning(s)