API 实现风车的旋转,该怎么解决
API 实现风车的旋转
这个程序不太懂 问题:不知道它是通过什么实现了 旋转 这个功能 它没有设置Timer ,控制角度的变化来实现旋转
希望高手解释下
include<windows.h>
#include<cmath>
#define PI 3.1415926
double fAngle;
int nNum=0;
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[]="Simon's Windows";
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,
CW_USEDEFAULT,
CW_USEDEFAULT,
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;
HBRUSH hBrush;
HPEN hp;
PAINTSTRUCT ps;
int nCenterX,nCenterY;
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,MM_ANISOTROPIC);
SetWindowExtEx(hdc,400,300,NULL);
SetViewportExtEx(hdc,600,450,NULL);
SetViewportOrgEx(hdc,200,200,NULL);
hp=CreatePen(PS_SOLID,1,BLACK_PEN);
LineTo(hdc,200,200);
hp=CreatePen(PS_SOLID,1,RGB(255,0,255));
SelectObject(hdc,hp);
Ellipse(hdc,-100,-100,100,100);
fAngle=2.0*PI/10*nNum;
nCenterX=(int)(50*sin(fAngle));
nCenterY=(int)(50*cos(fAngle));
hBrush=CreateSolidBrush(RGB(255,0,0));
SelectObject(hdc,hBrush);
Pie(hdc,nCenterX-50,nCenterY-50,nCenterX+50,nCenterY+50,(int)100*sin(fAngle),(int)100*cos(fAngle),0,0);
fAngle=2.0*PI/3+fAngle;
nCenterX=(int)(50*sin(fAngle));
nCenterY=(int)(50*cos(fAngle));
hBrush=CreateSolidBrush(RGB(255,255,0));
SelectObject(hdc,hBrush);
Pie(hdc,nCenterX-50,nCenterY-50,nCenterX+50,nCenterY+50,100*sin(fAngle),100*cos(fAngle),0,0);
fAngle=2.0*PI/3+fAngle;
nCenterX=(int)(50*sin(fAngle));
nCenterY=(int)(50*cos(fAngle));
hBrush=CreateSolidBrush(RGB(0,255,255));
SelectObject(hdc,hBrush);
Pie(hdc,nCenterX-50,nCenterY-50,nCenterX+50,nCenterY+50,100*sin(fAngle),100*cos(fAngle),0,0);
nNum++;
Sleep(100);
InvalidateRect(hwnd,NULL,1);
DeleteObject(hBrush);
EndPaint(hwnd,&ps);
return 0;
这个程序不太懂 问题:不知道它是通过什么实现了 旋转 这个功能 它没有设置Timer ,控制角度的变化来实现旋转
希望高手解释下
include<windows.h>
#include<cmath>
#define PI 3.1415926
double fAngle;
int nNum=0;
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[]="Simon's Windows";
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,
CW_USEDEFAULT,
CW_USEDEFAULT,
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;
HBRUSH hBrush;
HPEN hp;
PAINTSTRUCT ps;
int nCenterX,nCenterY;
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,MM_ANISOTROPIC);
SetWindowExtEx(hdc,400,300,NULL);
SetViewportExtEx(hdc,600,450,NULL);
SetViewportOrgEx(hdc,200,200,NULL);
hp=CreatePen(PS_SOLID,1,BLACK_PEN);
LineTo(hdc,200,200);
hp=CreatePen(PS_SOLID,1,RGB(255,0,255));
SelectObject(hdc,hp);
Ellipse(hdc,-100,-100,100,100);
fAngle=2.0*PI/10*nNum;
nCenterX=(int)(50*sin(fAngle));
nCenterY=(int)(50*cos(fAngle));
hBrush=CreateSolidBrush(RGB(255,0,0));
SelectObject(hdc,hBrush);
Pie(hdc,nCenterX-50,nCenterY-50,nCenterX+50,nCenterY+50,(int)100*sin(fAngle),(int)100*cos(fAngle),0,0);
fAngle=2.0*PI/3+fAngle;
nCenterX=(int)(50*sin(fAngle));
nCenterY=(int)(50*cos(fAngle));
hBrush=CreateSolidBrush(RGB(255,255,0));
SelectObject(hdc,hBrush);
Pie(hdc,nCenterX-50,nCenterY-50,nCenterX+50,nCenterY+50,100*sin(fAngle),100*cos(fAngle),0,0);
fAngle=2.0*PI/3+fAngle;
nCenterX=(int)(50*sin(fAngle));
nCenterY=(int)(50*cos(fAngle));
hBrush=CreateSolidBrush(RGB(0,255,255));
SelectObject(hdc,hBrush);
Pie(hdc,nCenterX-50,nCenterY-50,nCenterX+50,nCenterY+50,100*sin(fAngle),100*cos(fAngle),0,0);
nNum++;
Sleep(100);
InvalidateRect(hwnd,NULL,1);
DeleteObject(hBrush);
EndPaint(hwnd,&ps);
return 0;