最简单的MFC程序,链接中遇到的奇怪有关问题
最简单的MFC程序,链接中遇到的奇怪问题.
代码如下:
=========================================================================
PrintScreen.h
=========================================================================
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};
class CMyWnd : public CFrameWnd
{
public:
CMyWnd ();
protected:
afx_msg void OnPaint ();
DECLARE_MESSAGE_MAP ()
};
=========================================================================
PrintScreen.cpp
=========================================================================
#include <afxwin.h>
#include "PrintScreen.h "
CMyApp CMyApp;
BOOL CMyApp::InitInstance ()
{
m_pMainWnd=new CMyWnd;
m_pMainWnd-> ShowWindow (m_nCmdShow);
m_pMainWnd-> UpdateWindow ();
return true;
}
BEGIN_MESSAGE_MAP(CMyWnd,CFrameWnd)
ON_WM_PAINT ()
END_MESSAGE_MAP()
CMyWnd::CMyWnd()
{
Create(NULL,_T( "Text Window "));
}
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect (&rect);
dc.DrawText( _T( "This is a string "),&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
=========================================================================
VS2005,编译的时候遇到报错如下:
=========================================================================
------ 已启动生成: 项目: PrintScreen, 配置: Debug Win32 ------
正在编译...
PrintScreen.cpp
WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)
正在链接...
libcmt.lib(crt0.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
C:\Documents and Settings\edgeperson\My Documents\Visual Studio 2005\Projects\PrintScreen\Debug\PrintScreen.exe : fatal error LNK1120: 1 个无法解析的外部命令
生成日志保存在“file://c:\Documents and Settings\edgeperson\My Documents\Visual Studio 2005\Projects\PrintScreen\PrintScreen\Debug\BuildLog.htm”
PrintScreen - 2 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
=========================================================================
实在是不知道怎么办了````各位高手帮帮忙,谢谢
------解决方案--------------------
这个是LZ编译器设置的问题,属性页-〉连接-〉system->子系统修改一下。
------解决方案--------------------
#pragma comment(linker, "/subsystem:console")
加在程序的开头部分。
代码如下:
=========================================================================
PrintScreen.h
=========================================================================
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};
class CMyWnd : public CFrameWnd
{
public:
CMyWnd ();
protected:
afx_msg void OnPaint ();
DECLARE_MESSAGE_MAP ()
};
=========================================================================
PrintScreen.cpp
=========================================================================
#include <afxwin.h>
#include "PrintScreen.h "
CMyApp CMyApp;
BOOL CMyApp::InitInstance ()
{
m_pMainWnd=new CMyWnd;
m_pMainWnd-> ShowWindow (m_nCmdShow);
m_pMainWnd-> UpdateWindow ();
return true;
}
BEGIN_MESSAGE_MAP(CMyWnd,CFrameWnd)
ON_WM_PAINT ()
END_MESSAGE_MAP()
CMyWnd::CMyWnd()
{
Create(NULL,_T( "Text Window "));
}
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect (&rect);
dc.DrawText( _T( "This is a string "),&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
=========================================================================
VS2005,编译的时候遇到报错如下:
=========================================================================
------ 已启动生成: 项目: PrintScreen, 配置: Debug Win32 ------
正在编译...
PrintScreen.cpp
WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)
正在链接...
libcmt.lib(crt0.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
C:\Documents and Settings\edgeperson\My Documents\Visual Studio 2005\Projects\PrintScreen\Debug\PrintScreen.exe : fatal error LNK1120: 1 个无法解析的外部命令
生成日志保存在“file://c:\Documents and Settings\edgeperson\My Documents\Visual Studio 2005\Projects\PrintScreen\PrintScreen\Debug\BuildLog.htm”
PrintScreen - 2 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
=========================================================================
实在是不知道怎么办了````各位高手帮帮忙,谢谢
------解决方案--------------------
这个是LZ编译器设置的问题,属性页-〉连接-〉system->子系统修改一下。
------解决方案--------------------
#pragma comment(linker, "/subsystem:console")
加在程序的开头部分。