#include <windows.h> #include <stdlib.h> #include <string.h> #include <math.h> #define Pi 3.1415926long WINAPI WndProc (HWND hwnd, UINT iMessage, uint WParam, LONG lParam); BOOL Initwindowsclass (hinstance hinstance); BOOL initwindows (hinstance hinstance, int ncmdshow); int WINAPI WinMain (hinstance hinstance,hinstance hprevinstance, LPSTR lpcmdline, int ncmdshow) {MSG message;if (! Initwindowsclass (HINSTANCE)) return false;if (! Initwindows (HINSTANCE, nCmdShow)) return False;while (GetMessage (&message, 0, 0, 0)) {translatemessage (& Message);D ispatchmessage (&message);} return Message.wparam;} Long WINAPI WndProc (HWND hwnd, UINT iMessage, uint wParam, long LParam) {HDC hdc; Hpen Hpen; Paintstruct Ptstr; int n = 25; Point points[25];d ouble angel = 2 * pi/n;for (int i = 0; i < n; i++) {points[i].x = static_cast<long> (320 + 180 * cos (I*angel));p oints[i].y = static_cast<long> (+ +) sin (I*angel);} Switch (iMessage) {Case WM_PAINT:HDC = BeginPaint (HWnd,&PTSTR); for (int i = 0; i <; i++) {Hpen = (hpen) getstockobject (Null_pen); SelectObject (HDC, Hpen); LineTo (HDC, points[i].x, POINTS[I].Y); DeleteObject (Hpen); if (i = = 0) {for (int j = 1; j < N; j + +) {switch (j% 6) {case 1:case 2:hpen = CreatePen (ps_solid, 1, RGB (255, 0, 0)); Bre Ak;case 3:case 4:hpen = CreatePen (ps_solid, 1, RGB (0, 255, 0)); Break;case 5:case 0:hpen = CreatePen (ps_solid, 1, RGB (0, 0, 255)); break;} SelectObject (HDC, Hpen); LineTo (HDC, points[j].x, POINTS[J].Y); Movetoex (HDC, points[i].x, Points[i].y, NULL);D eleteobject (Hpen); }}else{for (Int j = i + 1; j < N; j + +) {switch (j% 6) {case 1:case 2:hpen = CreatePen (ps_solid, 1, RGB (255, 0, 0)); ; case 3:case 4:hpen = CreatePen (ps_solid, 1, RGB (0, 255, 0)); break;case 5:case 0:hpen = CreatePen (ps_solid, 1, RGB (0, 0, 2 55)); break;} SelectObject (HDC, Hpen); LineTo (HDC, points[j].x, POINTS[J].Y); Movetoex (HDC, points[i].x, Points[i].y, NULL);D eleteobject (Hpen); Sleep (50);}} EndPaint (HWnd, &Amp PTSTR); return 0;case wm_destroy:postquitmessage (0), Return 0;default:return (DefWindowProc (hWnd, IMessage, WParam, LParam));}} BOOL initwindows (hinstance hinstance, int ncmdshow) {HWND Hwnd;hwnd = CreateWindow ("Winfill", " Kaleidoscope ", Ws_overlappedwindow,cw_usedefault,0,cw_usedefault,0,null,null,hinsta Nce,null); if (!hwnd) return FALSE; ShowWindow (HWnd, ncmdshow); UpdateWindow (hWnd); return TRUE;} BOOL Initwindowsclass (hinstance hinstance) {wndclass wndclass; Wndclass.cbclsextra = 0; Wndclass.cbwndextra = 0; Wndclass.hbrbackground = (Hbrush) (Getstockobject (White_brush)); Wndclass.hcursor = LoadCursor (NULL, Idc_arrow); Wndclass.hicon = LoadIcon (NULL, "END"); Wndclass.hinstance = hinstance; Wndclass.lpfnwndproc = WndProc; Wndclass.lpszclassname = "Winfill"; Wndclass.lpszmenuname = NULL; Wndclass.style = Cs_hredraw | Cs_vredraw;return registerclass (&wndclass);}
Windows Programming-Kaleidoscope drawing