// Hello.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 functionBOOL 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);
}-------------------------------------------------------------------------------------
我调试的错误如下:
--------------------Configuration: Hello - Win32 Debug--------------------
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/Hello.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.Hello.exe - 3 error(s), 0 warning(s)
各位大虾帮我看看,这个程序哪里错了?
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 functionBOOL 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);
}-------------------------------------------------------------------------------------
我调试的错误如下:
--------------------Configuration: Hello - Win32 Debug--------------------
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/Hello.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.Hello.exe - 3 error(s), 0 warning(s)
各位大虾帮我看看,这个程序哪里错了?
就知道错在哪里了,这是学习vc很重要的方法!!!
导致你的Link错误的原因是你建立工程的方法不对,没有使用MFC。具体建立工程的步骤如下:
1、 File-->New | Projects | Win32 Application(注意是Win32 Application)
2、在下面填入你的工程目录和名字,如 HelloMFC、 d:\Exercise
3、接下来,选择建立一个空工程。点确定。
4、接下来出现工程配置的对话框,点确定。
5、File->New 添加一个hello.h的文件并填充内容进去:
//Hello.cpp
#include <afxwin.h>
#include "Hello.h"CMyApp myApp;///////////////////////////////////////////////////////////////////////////
//CMyApp member functionBOOL CMyApp::InitInstance()
{
m_pMainWnd=new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}6、添加一个 Hello.cpp 文件进去:#include <afxwin.h>
#include "Hello.h"CMyApp myApp;///////////////////////////////////////////////////////////////////////////
//CMyApp member functionBOOL 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);
}7. Project ---> Add to Project -->Files 选择Hello.h , Hello.cpp.
8. Project ---> Settings ---> General 页面。
将 Microsoft Foundation Class 下拉诓的选择项置为: Use MFC in a shared DLL
9. OK, F7 Build 整个工程。
10. Ctrl + F5 运行!That's all .