// feicheche.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include
#define PI 3.1415926
//定义变量
int n = 0,k = 101;
int i,num = 0,maxNum = 360;
POINT p[201],yp1[201],yp2[201],yp3[201];
double f,radious;
long WINAPI WndProc(
HWND hWnd,
UINT iMsg,
UINT wParam,
LONG lParam
);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
MSG Msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName="fengche";
wndclass.lpszMenuName=NULL;
wndclass.style=0;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hWnd = CreateWindow("fengche",
"风车",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd,SW_SHOWNORMAL);
UpdateWindow(hWnd);
for(n=0;n<=100;n++)
{
p[n].x=(long)(n*PI/100*40);
p[n].y=(long)(30*sin(n*PI/100));
}
for(n=101;n<=200;n++)
{
p[n].x=(long)(k*PI/101*40);
p[n].y=(long)(30*(-sin(k*PI/101)));
k--;
}
while(GetMessage(&Msg,0,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
long WINAPI WndProc(
HWND hWnd,
UINT iMsg,
UINT wParam,
LONG lParam
)
{
HDC hDC;
HBRUSH hBrush;
HPEN hPen;
PAINTSTRUCT PtStr;
switch(iMsg)
{
case WM_PAINT:
{
hDC=BeginPaint(hWnd,&PtStr);
SetWindowOrgEx(hDC,-400,-250,NULL);
//弧线弧度
f = 2*PI*num/maxNum;
//绘制叶片1
for(i=0;i<=200;i++)
{
yp1[0].x = 0;
yp1[0].y = 0;
radious = sqrt(p[i].x *p[i].x +p[i].y *p[i].y);
double x=(double)p[i].y/(double)p[i].x;
yp1[i].x=(long)(radious*cos(f+atan(x)));
yp1[i].y=(long)(radious*sin(f+atan(x)));
}
hBrush = CreateSolidBrush(RGB(255,0,0));
SelectObject(hDC,hBrush);
hPen = CreatePen(PS_SOLID,2,RGB(0,0,0));
SelectObject(hDC,hPen);
Polygon(hDC,yp1,201);
DeleteObject(hPen);
DeleteObject(hBrush);
//绘制叶片2
for(i=0;i<=200;i++)
{
yp2[0].x = 0;
yp2[0].y = 0;
radious = sqrt(p[i].x *p[i].x +p[i].y *p[i].y);
double x=(double)p[i].y/(double)p[i].x;
yp2[i].x=(long)(radious*cos(f+2*PI/3+atan(x)));
yp2[i].y=(long)(radious*sin(f+2*PI/3+atan(x)));
}
hBrush = CreateSolidBrush(RGB(0,255,0));
SelectObject(hDC,hBrush);
hPen = CreatePen(PS_SOLID,2,RGB(0,0,0));
SelectObject(hDC,hPen);
Polygon(hDC,yp2,201);
DeleteObject(hPen);
DeleteObject(hBrush);
//绘制叶片3
for(i=0;i<=200;i++)
{
yp3[0].x = 0;
yp3[0].y = 0;
radious = sqrt(p[i].x *p[i].x +p[i].y *p[i].y);
double x=(double)p[i].y/(double)p[i].x;
yp3[i].x=(long)(radious*cos(f+4*PI/3+atan(x)));
yp3[i].y=(long)(radious*sin(f+4*PI/3+atan(x)));
}
hBrush = CreateSolidBrush(RGB(0,0,255));
SelectObject(hDC,hBrush);
hPen = CreatePen(PS_SOLID,2,RGB(0,0,0));
SelectObject(hDC,hPen);
Polygon(hDC,yp3,201);
DeleteObject(hPen);
DeleteObject(hBrush);
num++;
Sleep(100);
if(num<1000)
InvalidateRect(hWnd,NULL,1);
EndPaint(hWnd,&PtStr);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
return (DefWindowProc(hWnd,iMsg,wParam,lParam));
}
return FALSE;
}