Windows Programming-Kaleidoscope drawing

Source: Internet
Author: User

#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,&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.