在VC++技术内幕一书中,在讲述应用框架时给出一例子如下:
myapp.h
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMyFrame : public CFrameWnd
{
public:
MyFrame();
protected:
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
myapp.cpp
#include <afxwin.h>
#include "myapp.h"
CMyApp NEAR theApp;
BOOL CMyApp::InitInstance();
{ //error C2447: missing function header (old-style formal list?) m_pMainWnd=new CMyFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
END_MESSAGE_MAP()
CMyFrame::MyFrame()
{
Creat("AfxFrameOrView","MYAPP Application");//error C2065: 'Creat' : undeclared identifier
}
void CMyFrame::OnLButtonDown(UINT nFlags,CPoint point)
{
TRACE("Entering CMyFrame::OnLButtonDown - %1x,%d,%d\n",
(long)nFlags,point.x,point.y);
}
void CMyFrame::OnPaint()
{
CPaintDC dc(this);
dc.TextOut(0,0,"Hello, world!");
}
但是编译时出现如下错误:
error C2447: missing function header (old-style formal list?)
error C2065: 'Creat' : undeclared identifier
错误所处的位置如程序所示。
请我的vc是6.0版,书是94年清华版的其中的例子可能是 基于vc1.0的
myapp.h
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMyFrame : public CFrameWnd
{
public:
MyFrame();
protected:
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
myapp.cpp
#include <afxwin.h>
#include "myapp.h"
CMyApp NEAR theApp;
BOOL CMyApp::InitInstance();
{ //error C2447: missing function header (old-style formal list?) m_pMainWnd=new CMyFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
END_MESSAGE_MAP()
CMyFrame::MyFrame()
{
Creat("AfxFrameOrView","MYAPP Application");//error C2065: 'Creat' : undeclared identifier
}
void CMyFrame::OnLButtonDown(UINT nFlags,CPoint point)
{
TRACE("Entering CMyFrame::OnLButtonDown - %1x,%d,%d\n",
(long)nFlags,point.x,point.y);
}
void CMyFrame::OnPaint()
{
CPaintDC dc(this);
dc.TextOut(0,0,"Hello, world!");
}
但是编译时出现如下错误:
error C2447: missing function header (old-style formal list?)
error C2065: 'Creat' : undeclared identifier
错误所处的位置如程序所示。
请我的vc是6.0版,书是94年清华版的其中的例子可能是 基于vc1.0的
解决方案 »
- AddFontResourceEx 从字体文件加载字体问题?
- 我的程序需要在 64bit XP下运行,需要注意什么?
- 关于OnPaint函数,如何使用其它类的成员变量??
- 对话框怎么实现滚动显示?
- 程序如何复制自身?进来抢分咯
- 网络监视器——一个网络开发辅助工具
- 请问一下MTS 与COM DCOM COM+ 的关系?不好意思 ^-^
- 这种错误是怎么搞的?
- 请问:如何指定MM_ANISOTROPIC映象方式的坐标增长方式,使X轴向右为正向,Y轴向上为正!谢谢!
- WIN2000的IIS5中的FTP站点如何才能让别人登录进来时要输入用户名和密码,谢谢!
- 能不能共享一个udp通信的例子??? 赠100分
- 大家用过WINDOWS的NET SEND 命令吗?
try again will be ok.
给你一个新版本的hello worldHello.h
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};class CMainWindow : public CFrameWnd
{
public:
CMainWindow ();protected:
afx_msg void OnPaint ();
DECLARE_MESSAGE_MAP ()
};Hello.cpp
#include <afxwin.h>
#include "Hello.h"CMyApp myApp;/////////////////////////////////////////////////////////////////////////
// CMyApp member functionsBOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functionsBEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_PAINT ()
END_MESSAGE_MAP ()CMainWindow::CMainWindow ()
{
Create (NULL, _T ("The Hello Application"));
}void CMainWindow::OnPaint ()
{
CPaintDC dc (this);
CRect rect;
GetClientRect (&rect); dc.DrawText (_T ("Hello, MFC"), -1, &rect,
DT_SINGLELINE ¦ DT_CENTER ¦ DT_VCENTER);
}
"Creat"改为"Create"
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
libcd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/hello.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.hello.exe - 4 error(s), 0 warning(s)
2.加入文件hello.h, hello.cpp;
3.在该工程中,对菜单操作 project->settings,出现属性表,在general属性页,
在下拉框中选中 :use MFC in a shared dll(默认选中的是:not using MFC)
--------------------Configuration: hello - Win32 Debug--------------------
Linking...
msvcrtd.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/hello.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.hello.exe - 2 error(s), 0 warning(s)
也不是没有办法project->settings,在link属性页,在Category下拉框,选中Output, 然后在Entry-point symbol 下方的编辑框中写入 WinMainCRTStartup,然后再编译执行