1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| #include <windows.h> #include <math.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); void DrawFiveStarFlag(HDC hdc, int x, int y, int w); void DrawFivePointedStar(HDC hdc, int x, int y, int r, float d);
HINSTANCE hInst;
TCHAR szClassName[] = TEXT("WindowsApp");
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl;
hInst = hThisInstance; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
if (!RegisterClassEx (&wincl)) return 0;
hwnd = CreateWindowEx ( 0, szClassName, TEXT("TestPie"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, HWND_DESKTOP, NULL, hThisInstance, NULL );
ShowWindow (hwnd, nFunsterStil);
while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); }
return messages.wParam; }
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc;
switch (message) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); DrawFiveStarFlag(hdc, 50, 50, 300); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); }
return 0; }
void DrawFivePointedStar(HDC hdc, int x, int y, int r, float d) { float r0 = 0.381966*r; int i; POINT p[10];
for(i=0; i<5; i++) { p[2*i].x = x + r*cos((i*72-18+d)*M_PI/180); p[2*i].y = y + r*sin((i*72-18+d)*M_PI/180);
p[2*i+1].x = x + r0*cos((i*72+18+d)*M_PI/180); p[2*i+1].y = y + r0*sin((i*72+18+d)*M_PI/180); }
Polygon(hdc, p, 10); }
void DrawFiveStarFlag(HDC hdc, int x, int y, int w) { COLORREF RED = RGB(255, 0, 0), YELLOW = RGB(255, 255, 0); HPEN hPen1 = CreatePen(PS_SOLID, 1, RED), hPen2 = CreatePen(PS_SOLID, 1, YELLOW); HBRUSH hBrush1 = CreateSolidBrush(RED), hBrush2 = CreateSolidBrush(YELLOW);
SelectObject(hdc, hPen1); SelectObject(hdc, hBrush1); Rectangle(hdc, x, y, x+w, y+2*w/3);
SelectObject(hdc, hPen2); SelectObject(hdc, hBrush2); DrawFivePointedStar(hdc, x+w/6, y+w/6, w/10, 0); DrawFivePointedStar(hdc, x+w/3, y+w/15, w/30, 18); DrawFivePointedStar(hdc, x+2*w/5, y+2*w/15, w/30, 45); DrawFivePointedStar(hdc, x+2*w/5, y+7*w/30, w/30, 9); DrawFivePointedStar(hdc, x+w/3, y+3*w/10, w/30, 27);
DeleteObject(hPen1); DeleteObject(hPen2); DeleteObject(hBrush1); DeleteObject(hBrush2); }
|