#include<windows.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
POINT point[100];
double pai=3.1415926;
int i=0,j=0;
long c;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[] = "正弦运动";
char lpszTitle[] = "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;
PAINTSTRUCT ps;
HPEN hP;
HBRUSH hB;
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SetMapMode(hdc,MM_TEXT);
hP=CreatePen(PS_SOLID,2,RGB(255,0,0));
SelectObject(hdc,hP);
for(i=0;i<100;i++)
{
point[i].x = (long)(i*2*pai/100*100+200);
point[i].y = (long)(-100*sin(i*2*pai/100)+200);
}
Polyline(hdc,point,100);
if(j%100<=25)
{
hP=CreatePen(PS_SOLID,6,RGB(255,255,0));
hB=CreateSolidBrush(RGB(0,0,0));
}
else if(j%100<=50)
{
hP=CreatePen(PS_SOLID,6,RGB(255,0,255));
hB=CreateSolidBrush(RGB(0,0,255));
}
else if(j%100<=75)
{
hP=CreatePen(PS_SOLID,6,RGB(0,255,255));
hB=CreateSolidBrush(RGB(0,255,0));
}
else
{
hP=CreatePen(PS_SOLID,6,RGB(0,0,0));
hB=CreateSolidBrush(RGB(255,0,0));
}
SelectObject(hdc,hP);
SelectObject(hdc,hB);
c=(long)(j%25*1.6+20);
Ellipse(hdc,point[j%100].x-c,point[j%100].y-c,point[j%100].x+c,point[j%100].y+c);
InvalidateRect(hwnd,NULL,1);
Sleep(100);
j++;
EndPaint(hwnd,&ps);
DeleteObject(hB);
DeleteObject(hP);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}