MainFrm.cpp 的代码如下:
--------------------------------------------------------------------#include "stdafx.h"
#include "ModalDlg.h"#include "MainFrm.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(IDM_POPUPMODALDLG, OnPopupmodaldlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()static UINT indicators[] =
{
ID_SEPARATOR,           // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destructionCMainFrame::CMainFrame()
{
// TODO: add member initialization code here

}CMainFrame::~CMainFrame()
{
}int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;      // fail to create
} if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
  sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1;      // fail to create
} // TODO: Delete these three lines if you don't want the toolbar to
//  be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar); return 0;
}BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs return TRUE;
}/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnPopupmodaldlg() 
{
CModalDlg ModalDlg;
CModalDlg.DoModal();
// TODO: Add your command handler code here
  
}
编译出现错误如下:
D:\MyProjects\ModalDlg\MainFrm.cpp(110) : error C2065: 'CModalDlg' : undeclared identifier
D:\MyProjects\ModalDlg\MainFrm.cpp(110) : error C2146: syntax error : missing ';' before identifier 'ModalDlg'
D:\MyProjects\ModalDlg\MainFrm.cpp(110) : error C2065: 'ModalDlg' : undeclared identifier
D:\MyProjects\ModalDlg\MainFrm.cpp(111) : error C2228: left of '.DoModal' must have class/struct/union type我都要郁闷死了,我都是按照教程上做的,竟然老是出错误拜求达人解答!!!

解决方案 »

  1.   

    CModalDlg.DoModal();
    DoModal() 不是静态函数
      

  2.   

    void CMainFrame::OnPopupmodaldlg() 
    {
    CModalDlg ModalDlg;
    CModalDlg.DoModal();
    // TODO: Add your command handler code here
      
    }----------------------------------------         CModalDlg ModalDlg;
             ModalDlgDlg.DoModal();耐心点,细心点
      

  3.   

    D:\MyProjects\ModalDlg\MainFrm.cpp(110) : error C2146: syntax error : missing ';' before identifier 'ModalDlg'少个分号,加上,估计前3个报错就没了
      

  4.   

    这一般不是少分号,估计是头文件包含不正确.
    换句话说,CModalDlg这个类不认.
      

  5.   

    void CMainFrame::OnPopupmodaldlg() 
    {
    CModalDlg ModalDlg;
    CModalDlg.DoModal();   //////////注意这里,应该是ModalDlg.DoModal();
    // TODO: Add your command handler code here
      
    }
      

  6.   

    CModalDlg ModalDlg;
    CModalDlg.DoModal();   //////////注意这里,应该是ModalDlg.DoModal();
    呵呵,还有么就是包含不正确,你看看#include "ModalDlg.h"
    ModalDlg.h的protected改成public看看
      

  7.   

    不过其实CModalDlg.DoModal();  不过其实这句话应该不会报错的。
    我看看应该是"ModalDlg.h"里的问题
      

  8.   

    把含有“InitInstance”这个函数的头文件加上看看。
    注意包含的顺序。
    这个头文件应该在#include "stdafx.h"后面的,紧跟。
      

  9.   

    将 CMdodalDlg.DoModal();改成ModalDlg.DoModal();好像也同样会报错出错提示为:
    D:\MyProjects\ModalDlg\MainFrm.cpp(110) : error C2065: 'CModalDlg' : undeclared identifier
    D:\MyProjects\ModalDlg\MainFrm.cpp(110) : error C2146: syntax error : missing ';' before identifier 'ModalDlg'
    D:\MyProjects\ModalDlg\MainFrm.cpp(110) : error C2065: 'ModalDlg' : undeclared identifier
    D:\MyProjects\ModalDlg\MainFrm.cpp(111) : error C2228: left of '.DoModal' must have class/struct/union type
    Error executing cl.exe.----------------------------------------------------------------------------ModalDlg.h文件为:// ModalDlg.h : main header file for the MODALDLG application
    //#if !defined(AFX_MODALDLG_H__07101502_C707_4C8D_ACA1_F399B033FF7B__INCLUDED_)
    #define AFX_MODALDLG_H__07101502_C707_4C8D_ACA1_F399B033FF7B__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000#ifndef __AFXWIN_H__
    #error include 'stdafx.h' before including this file for PCH
    #endif#include "resource.h"       // main symbols/////////////////////////////////////////////////////////////////////////////
    // CModalDlgApp:
    // See ModalDlg.cpp for the implementation of this class
    //class CModalDlgApp : public CWinApp
    {
    public:
    CModalDlgApp();// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CModalDlgApp)
    public:
    virtual BOOL InitInstance();
    //}}AFX_VIRTUAL// Implementation
    //{{AFX_MSG(CModalDlgApp)
    afx_msg void OnAppAbout();
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    ///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MODALDLG_H__07101502_C707_4C8D_ACA1_F399B033FF7B__INCLUDED_)
    ------------------------------------大家帮忙看看是不是ModalDlg.h里的错误
      

  10.   

    CMdodalDlg
    这个类根本没定义 :(需要定义这个Dialog类,
    你可以用MFCWizard 新建一个工程看看CAboutDlg,学习一下。
      

  11.   

    void CMainFrame::OnPopupmodaldlg() 
    {
    CModalDlg ModalDlg;
    CModalDlg.DoModal();  ======>改为: ModalDlg.DoModal();DoModal不是静态函数,所以应该用类的实例去调用。楼主粗心了。
    // TODO: Add your command handler code here
      
    }
      

  12.   

    楼上的,好像的确不是 CModalDlg.DoModal();  ======>改为: ModalDlg.DoModal();
    的问题,ModalDlg.h文件出现的问题啊
      

  13.   

    CModalDlg这个类没有定义, 鉴定完毕.
      

  14.   

    天。我原来,在MainFrm.cpp中对于 对话框的头文件的包含出现了错误~~
    忘记加上 该模式对话的头文件了
    然后CModalDlg.DoModal();=====>ModalDlg.DoModal();