编译环境vc6.0,文件扩展名是cpp。
#includeWindows.h
#includetchar.h
#includemath.h
longWINAPIWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam);
UINTSCREEN_WIDTH=1000;
UINTSCREEN_HEIGHT=600;
intWINAPIWinMain(HINSTANCEhInstance,
HINSTANCEhPrevInstance,
LPSTRlpCmdLine,
intnCmdShow)
{
TCHARclassName[]=_T(\"serenesunny\");
TCHARwindowName[]=_T(\"五角星\");
WNDCLASSwndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(hInstance,IDC_ARROW);
wndcls.hIcon=LoadIcon(hInstance,IDI_APPLICATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WndProc;
wndcls.lpszClassName=className;
wndcls.lpszMenuName=0;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(
HWNDhWnd=CreateWindow(className,windowName,WS_OVERLAPPEDWINDOW,0,
0,SCREEN_WIDTH,SCREEN_HEIGHT,0,0,hInstance,0);
ShowWindow(hWnd,SW_SHOWNORMAL);
UpdateWindow(hWnd);
MSGmsg;
while(GetMessage(
DispatchMessage(
}
returnmsg.wParam;
}
#definePi3.1415926
doublen=sin(3*Pi/(double)10)/sin(Pi/(double)10);//半径之比
intti=0;//旋转变量
UINTindex=0;
UINTr[]={(UINT)(n*20),20};
floattheta[]={(float)(-Pi/2),(float)(Pi/(float)5-Pi/2)};
POINTpoints[10];
UINTcenterx=100;
UINTcentery=SCREEN_HEIGHT/2;
longWINAPIWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam)
{
HDChdc;
PAINTSTRUCTps;
HBRUSHhBrush;
// HPENhPen;
inti;
intindex;
switch(message)
{
caseWM_CREATE:
caseWM_PAINT:
hdc=BeginPaint(hWnd,
hBrush=CreateSolidBrush(0x00ffff);
SelectObject(hdc,hBrush);
centerx=100ti;
centery=SCREEN_HEIGHT/2-(long)(200*sin(Pi*ti/(double)300));
for(index=0;index5;index)
{
for(i=0;i2;i)
{
points[index*2i].x=(long)(centerxr*cos(thetaindex*2*Pi/5));
points[index*2i].y=(long)(centeryr*sin(thetaindex*2*Pi/5));
}
}
Polygon(hdc,points,10);//把五角星看成一个10边形,用多边形画法去画
DeleteObject(hBrush);
ti=2;
ti=ti%600;
Sleep(20);
InvalidateRect(hWnd,NULL,1); //重绘窗口区域.
EndPaint(hWnd,
break;
caseWM_CLOSE:
DestroyWindow(hWnd);
break;
caseWM_DESTROY:
PostQuitMessage(0);
break;
default:
returnDefWindowProc(hWnd,message,wParam,lParam);
}
return0;
}
如果出现错误:
LIBCD.lib(crt0.obj):errorLNK2001:unresolvedexternalsymbol_main
解决方法:
控制台项目要使用windows子系统,而不是console,设置:
[Project]--[Settings]--选择\"Link\"属性页,
在ProjectOptions中将/subsystem:console改成/subsystem:windows. |