Professional Documents
Culture Documents
#include <windows.h>
#include <math.h>
#define NUM 1000
#define TWOPI (2 * 3.14159)
int a[3][6] = { { 123, 343, 100, 163, 232, 166 }, { 128, 15, 129, 74, 234, 255 }, { 1,
2, 3, 4, 1, 4 } };
int circle(HWND hwnd, HDC hdc, int i, int j, int dir, RECT rect, int nr)
{
HPEN hYellowPen;
HBRUSH hRedBrush;
hYellowPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 0));
hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
if (j + 150>rect.bottom)
{
if (dir == 1)a[2][nr] = 2; else a[2][nr] = 3;
}
if (i + 150>rect.right)
{
if (dir == 2)a[2][nr] = 3; else a[2][nr] = 4;
}
if (j + 50<rect.top)
{
if (dir == 3)a[2][nr] = 4; else a[2][nr] = 1;
}
if (i + 50<rect.left)
{
if (dir == 4)a[2][nr] = 1; else a[2][nr] = 2;
}
switch (a[2][nr])
{
case 1:{
a[0][nr]++; a[1][nr]++; break;
}
case 2:{
a[0][nr]++; a[1][nr]--; break;
}
case 3:{
a[0][nr]--; a[1][nr]--; break;
}
case 4:{
a[0][nr]--; a[1][nr]++; break;
}
}
switch (nr)
{
case 0:{SelectObject(hdc, hYellowPen); SelectObject(hdc, hRedBrush); break; }
}
Rectangle(hdc, a[0][nr] + 50, a[1][nr] + 50, a[0][nr] + 150, a[1][nr] + 150);
DeleteObject(hYellowPen);
DeleteObject(hRedBrush);
return dir;
}
switch (iMsg)
{
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &PaintStruct);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);