编了一个小程序,编译通过了,可是连接时出现错误,高手帮忙看看什么问题~
源代码如下
#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="映像模式";
char lpszTitle[]="My_Map_Mode";
wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow( lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
310,
330,
NULL,
NULL,
hInstance,
NULL);
ShowWindow( hwnd,nCmdShow);
UpdateWindow(hwnd);
while( GetMessage(&Msg,NULL,0,0))
{
TranslateMessage( &Msg);
DispatchMessage( &Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
HDC hdc;
static PAINTSTRUCT ps;
static HBRUSH hBl;
static HPEN hPl;
static int nMode;
static int flags=0;
static int nlbuttonx=0,nlbuttony=0;
int i=0;
switch(message){
case WM_CREATE:
flags=0;
nMode=MM_TEXT;
hBl=(HBRUSH)GetStockObject(BLACK_BRUSH);
break;
case WM_LBUTTONDOWN:
flags=1;
nMode=MM_ISOTROPIC;
nlbuttonx=LOWORD(lParam);
nlbuttony=HIWORD(lParam);
hBl=(HBRUSH)GetStockObject(BLACK_BRUSH);
InvalidateRect(hwnd,NULL,0);
break;
case WM_RBUTTONDOWN:
nMode=MM_ANISOTROPIC;
nlbuttonx=LOWORD(lParam);
nlbuttony=HIWORD(lParam);
hBl=CreateSolidBrush(RGB(0,255,0));
InvalidateRect(hwnd,NULL,0);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,nMode);
SetWindowExtEx(hdc,300,300,NULL);
SetWindowOrgEx(hdc,0,0,NULL);
SetViewportExtEx(hdc,300,300,NULL);
hPl=CreatePen(PS_INSIDEFRAME,2,RGB(125,125,125));
SelectObject(hdc,hPl);
SelectObject(hdc,hBl);
if(flags)
{
SetMapMode(hdc,nMode);
Ellipse(hdc,
(nlbuttonx/30)*30,
(nlbuttony/30)*30,
(nlbuttonx/30)*30+30,
(nlbuttonx/30)*30+30);
}
else
{
for(i=30;i<=300;)
{
MoveToEx(hdc,i,0,NULL);
LineTo(hdc,i,300);
i=i+30;
}
for(i=30;i<=300;)
{
MoveToEx(hdc,0,i,NULL);
LineTo(hdc,300,i);
i=i+30;
}
}
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
DeleteObject(hBl);
DeleteObject(hPl);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
错误如下
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/网格.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.