谁遇到过这个问题?
我所输的程序代码是:
#include<windows.h>
#include<stdlib.h>
#include<string.h>
long WINAPI WndProc(HWND hwnd,UINT imessage,UINT wparam,
LONG lparam);
BOOL initwindowsclass(HINSTANCE hinstance);
BOOL initwindows(HINSTANCE hinstance,int ncmdshow);
HWND hwndmain;
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance
,LPSTR lpCmdLine,int nCmdShow)
{
MSG Message;
if(!initwindowsclass(hinstance))
return FALSE;
if(!initwindows(hinstance,nCmdShow))
return FALSE;
while(GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
long WINAPI WndProc(HWND hwnd,UINT imessage,UINT wparam,
LONG lparam)
{
HDC hdc;
HBRUSH hbrush;
HPEN hpen;
PAINTSTRUCT ptstr;
switch(imessage)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ptstr);
SetMapMode(hdc,MM_ANISOTROPIC);
hpen=(HPEN)GetStockObject(BLACK_PEN);
hbrush=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
SelectObject(hdc,hbrush);
SelectObject(hdc,hpen);
RoundRect(hdc,50,120,100,200,15,15);
hbrush=(HBRUSH)GetStockObject(LTGRAY_BRUSH);
SelectObject(hdc,hbrush);
Ellipse(hdc,150,50,200,150);
hbrush=(HBRUSH)GetStockObject(HOLLOW_BRUSH);
SelectObject(hdc,hbrush);
Pie(hdc,250,50,300,100,250,50,300,50);
EndPaint(hwnd,&ptstr);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return(DefWindowProc(hwnd,imessage,wparam,lparam));
}
}
//初始化窗口
BOOL initwindows(HINSTANCE hinstance,int nCmdShow)
{
HWND hwnd;
hwnd=CreateWindow("winfill",
"填充示例程序",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hinstance,
NULL);
if(!hwnd)
return FALSE;
hwndmain=hwnd;
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
BOOL initwindowsclass(HINSTANCE hinstance)
{
WNDCLASS wndclass;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hbrBackground =(HBRUSH)(GetStockObject(WHITE_BRUSH));
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon =LoadIcon(NULL,"END");
wndclass.hInstance =hinstance;
wndclass.lpfnWndProc =WndProc;
wndclass.lpszClassName ="winfill";
wndclass.lpszMenuName =NULL;
wndclass.style =CS_HREDRAW;
return RegisterClass(&wndclass);
}
在首次运行是没有问题,但当退出VC环境再进入后执行时就出现了这样的提示:
--------------------Configuration: Huitu - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Huitu.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Huitu.exe - 2 error(s), 0 warning(s)