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我都要郁闷死了,我都是按照教程上做的,竟然老是出错误拜求达人解答!!!
--------------------------------------------------------------------#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我都要郁闷死了,我都是按照教程上做的,竟然老是出错误拜求达人解答!!!
解决方案 »
- ado编程 编译时发现QueryInterface”的左边必须指向类/结构/联合/泛型类型
- 关与MDI多文档程序视图切换问题
- 小菜我继续提问:请教大家如何理解LPCTSTR lpszAppName
- 第三方的控件
- 一个别人的任意软件,它在后台运行,如何给它模拟发送键盘消息?
- ActiveX打包发布问题
- 请教一个SDI程序视图显示问题。
- 怎么得到基于对话框的程序的窗体的HWND啊
- 请问各位VC 高手,行家在VC6.0中怎样使用控件(象VB中一样?不是吧!)一定高分送上!!!
- 各位同仁,我用DELPHI有两年了,有点厌倦了,近来一直学习VC++,且C++语言已学完,感觉还好,我打算学更多的VC,不知道现在是学MFC还是什么好?请高人指点我下一步学什么?72分相送,只有这么多
- 在用双缓存显示位图时候,BoundsChecker检测出了debug下的奇怪问题
- 怎么用VC编写 浏览器 按钮 插件???急急急!!!:?
DoModal() 不是静态函数
{
CModalDlg ModalDlg;
CModalDlg.DoModal();
// TODO: Add your command handler code here
}---------------------------------------- CModalDlg ModalDlg;
ModalDlgDlg.DoModal();耐心点,细心点
换句话说,CModalDlg这个类不认.
{
CModalDlg ModalDlg;
CModalDlg.DoModal(); //////////注意这里,应该是ModalDlg.DoModal();
// TODO: Add your command handler code here
}
CModalDlg.DoModal(); //////////注意这里,应该是ModalDlg.DoModal();
呵呵,还有么就是包含不正确,你看看#include "ModalDlg.h"
ModalDlg.h的protected改成public看看
我看看应该是"ModalDlg.h"里的问题
注意包含的顺序。
这个头文件应该在#include "stdafx.h"后面的,紧跟。
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里的错误
这个类根本没定义 :(需要定义这个Dialog类,
你可以用MFCWizard 新建一个工程看看CAboutDlg,学习一下。
{
CModalDlg ModalDlg;
CModalDlg.DoModal(); ======>改为: ModalDlg.DoModal();DoModal不是静态函数,所以应该用类的实例去调用。楼主粗心了。
// TODO: Add your command handler code here
}
的问题,ModalDlg.h文件出现的问题啊
忘记加上 该模式对话的头文件了
然后CModalDlg.DoModal();=====>ModalDlg.DoModal();