自己写了个练习类的代码,出现了连接错误,请各位大侠帮忙,在下感激不尽!!
错误:Compiling...winmain.cpp
Linking...
winmain.obj : error LNK2001: unresolved external symbol "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
Debug/cash.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
代码如下:请各位帮忙啊,在下感激不尽!~
#include <windows.h>
//#include <windef.h>
#include <stdio.h>
class create
{
public:
BOOL CreateWindow2(
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
BOOL ShowWindow2(
//HWND hWnd,
int nCmdShow
);
BOOL UpdateWindow2(
//HWND hWnd // handle to window
);
public:
HWND hWnd2;
};
//.....................................................................
BOOL create::CreateWindow2(
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
)
{
hWnd2=::CreateWindow(lpClassName,lpWindowName,
dwStyle,x,y,nWidth,nHeight,
hWndParent,hMenu, hInstance, lpParam
);
if(hWnd2!=NULL)
return TRUE;
else
return FALSE;
}
BOOL create::ShowWindow2(
//HWND hWnd,
int nCmdShow
)
{
return ::ShowWindow(hWnd2,nCmdShow);
}
BOOL create::UpdateWindow2()
{
return ::UpdateWindow(hWnd2);
}
//....................................................................
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
//.....................................................................
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS window;
window.cbClsExtra=0;
window.cbWndExtra=0;
window.hbrBackground=(HBRUSH )COLOR_WINDOW;
window.hCursor=0;
window.hIcon=LoadIcon(NULL,IDI_WINLOGO);
window.hInstance=hInstance;
window.lpfnWndProc=WindowProc;
window.lpszClassName="classone";
window.lpszMenuName=0;
window.style=CS_VREDRAW | CS_HREDRAW;
RegisterClass(&window);
create mainwindow;
mainwindow.CreateWindow2("classone","mainwindow",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,600,400,NULL,NULL,hInstance,NULL);
mainwindow.ShowWindow2(nCmdShow);
mainwindow.UpdateWindow2();
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char code is %d",wParam);
MessageBox(hwnd,szChar,"char",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","message",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"程序员",strlen("程序员"));
//ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"菜鸟",strlen("菜鸟"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
[ 本帖最后由 纯黑色 于 2010-5-10 22:58 编辑 ]