#include <windows.h>
HINSTANCE hInst;
HINSTANCE hInstance;
MSG msg;
char lpszClassName[]="Window_class";
char* ShowText;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);class CFrameWnd  
{
public:
HWND hWnd;
public:
int RegisterWindow();
void Create(LPCTSTR lpClassName,LPCTSTR lpWindowName);
void ShowWindow(int nCmdShow);
void UpdateWindow();
};int CFrameWnd::RegisterWindow()
{
WNDCLASS wc;
wc.style=0;
wc.lpfnWndProc=::WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=lpszClassName;
wc.lpszClassName=lpszClassName;
return RegisterClass(&wc);
}void CFrameWnd::Create(LPCTSTR lpClassName,LPCTSTR lpWindowName)
{
RegisterWindow();
hInst=hInstance;
hWnd=CreateWindow(lpszClassName,lpWindowName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
}void CFrameWnd::ShowWindow(int nCmdShow)
{
::ShowWindow(hWnd,nCmdShow);
}void CFrameWnd::UpdateWindow()
{
::UpdateWindow(hWnd);
}class CWinApp
{
public:
CFrameWnd* m_pMainWnd;
public:
virtual BOOL InitInstance(int nCmdShow);
int Run();
};int CWinApp::Run()
{
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}class CMyApp:public CWinApp
{
public:
BOOL InitInstance(int nCmdShow);
};
//CMyApp::InitInstance(int nCmdShow)
CMyApp::InitInstance(int nCmdShow)
{
m_pMainWnd=new CFrameWnd;
m_pMainWnd->Create(NULL,"New Encapsulated Windows Program");
m_pMainWnd->ShowWindow(nCmdShow);
m_pMainWnd->UpdateWindow();
return true;
}CMyApp theApp;int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
int ResultCode=-1;
theApp.InitInstance(nCmdShow);
return ResultCode=theApp.Run();
}LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_LBUTTONDOWN:
ShowText="Hello!";
InvalidateRect(hWnd,NULL,1);
break;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,50,50,ShowText,10);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
link的时候出现错误:
--------------------Configuration: MFC_Eg0202 - Win32 Debug--------------------
Linking...
main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CWinApp::InitInstance(int)" (?InitInstance@CWinApp@@UAEHH@Z)
Debug/MFC_Eg0202.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.MFC_Eg0202.exe - 2 error(s), 0 warning(s)请帮忙分析分析,谢谢