|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- HDC hdc;
- PAINTSTRUCT ps;
- POINT star[5];
- POINT starcenter;
- int r,i;
- HBRUSH hRedBrush,hOldBrush,hBrush,hBlueBrush;
- HPEN hRedPen, hOldPen;
- static int cxClient, cyClient;
- switch (message)
- {
- case WM_SIZE:
- cxClient = LOWORD(lParam);
- cyClient = HIWORD(lParam);
- return 0;
- case WM_PAINT:
- hdc = BeginPaint(hwnd, &ps);
-
- //确定五角星半径
- if (cxClient >= cyClient)
- {
- r = cyClient / 5;
- }
- else
- {
- r = cxClient / 5;
- }
-
- //绘制中心五角心
-
- starcenter.x = cxClient / 2;
- starcenter.y = cyClient / 2;
- //左上点
- star[0].x = starcenter.x - (int)(r*sin(2 * PI / 5));
- star[0].y = starcenter.y - (int)(r*cos(2 * PI / 5));
- //右上点
- star[1].x = starcenter.x + (int)(r*sin(2 * PI / 5));
- star[1].y = starcenter.y - (int)(r*cos(2 * PI / 5));
- //左下点
- star[2].x = starcenter.x - (int)(r*sin(PI / 5));
- star[2].y = starcenter.y + (int)(r*cos(PI / 5));
- //顶点
- star[3].x = starcenter.x;
- star[3].y = starcenter.y - r;
- //右下点
- star[4].x = starcenter.x + (int)(r*sin(PI / 5));
- star[4].y = starcenter.y + (int)(r*cos(PI / 5));
- if (cxClient >= cyClient)
- {
- //画外层红圈
- hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
- hOldBrush = SelectObject(hdc, hRedBrush);
- Ellipse(hdc, (cxClient - cyClient) / 2, 0, (cxClient + cyClient) / 2, cyClient);
- SelectObject(hdc, hOldBrush);
- //画内存白圈
- hBrush = GetStockObject(DC_BRUSH);
- hOldBrush = SelectObject(hdc, hBrush);
- Ellipse(hdc, (cxClient - cyClient) / 2 + cyClient / 10, cyClient / 10, (cxClient + cyClient) / 2 - cyClient / 10, cyClient * 9 / 10);
- SelectObject(hdc, hOldBrush);
- //画最内层红圈
- hOldBrush = SelectObject(hdc, hRedBrush);
- Ellipse(hdc, (cxClient - cyClient) / 2 + cyClient / 5, cyClient / 5, (cxClient + cyClient) / 2 - cyClient / 5, cyClient * 4 / 5);
- SelectObject(hdc, hRedBrush);
- //画五角星蓝色背景
- hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
- hOldBrush = SelectObject(hdc, hBlueBrush);
- Ellipse(hdc, (cxClient - cyClient) / 2 + cyClient * 3 / 10, cyClient * 3 / 10, (cxClient + cyClient) / 2 - cyClient * 3 / 10, cyClient * 7 / 10);
- DeleteObject(SelectObject(hdc, hOldBrush));
- //画中心五角星
- SelectObject(hdc, hRedBrush);
- SetPolyFillMode(hdc,WINDING);
- Polygon(hdc, star, 5);
- DeleteObject(SelectObject(hdc, hRedBrush));
- //覆盖五角星内部多余的线
- hRedPen = CreatePen(PS_SOLID, 0, RGB(255, 0, 0));
- hOldPen = SelectObject(hdc, hRedPen);
- MoveToEx(hdc, star[0].x, star[0].y, NULL);
- for (i = 1; i < 5; i++)
- {
- LineTo(hdc, star[i].x, star[i].y);
- }
- LineTo(hdc, star[0].x, star[0].y);
- DeleteObject(SelectObject(hdc, hOldPen));
- }
- else
- {
- hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
- hOldBrush = SelectObject(hdc, hRedBrush);
- Ellipse(hdc, 0, (cyClient - cxClient) / 2, cxClient, (cyClient + cxClient) / 2);
- SelectObject(hdc, hRedBrush);
- hBrush = GetStockObject(DC_BRUSH);
- hOldBrush = SelectObject(hdc, hBrush);
- Ellipse(hdc, cxClient / 10, (cyClient - cxClient) / 2 + cxClient / 10, cxClient - cxClient / 10, (cyClient + cxClient) / 2 - cxClient / 10);
- SelectObject(hdc, hOldBrush);
- hOldBrush = SelectObject(hdc, hRedBrush);
- Ellipse(hdc, cxClient / 5, (cyClient - cxClient) / 2 + cxClient / 5, cxClient - cxClient * 2 / 10, (cyClient + cxClient) / 2 - cxClient * 2 / 10);
- SelectObject(hdc, hOldBrush);
- hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
- hOldBrush = SelectObject(hdc, hBlueBrush);
- Ellipse(hdc, cxClient * 3 / 10, (cyClient - cxClient) / 2 + cxClient * 3 / 10, cxClient - cxClient * 3 / 10, (cyClient + cxClient) / 2 - cxClient * 3 / 10);
- DeleteObject(SelectObject(hdc, hOldBrush));
- hOldBrush = SelectObject(hdc, hRedBrush);
- SetPolyFillMode(hdc, WINDING);
- Polygon(hdc, star, 5);
- DeleteObject(SelectObject(hdc, hOldBrush));
- hRedPen = CreatePen(PS_SOLID, 0, RGB(255, 0, 0));
- hOldPen = SelectObject(hdc, hRedPen);
- MoveToEx(hdc, star[0].x, star[0].y, NULL);
- for (i = 1; i < 5; i++)
- {
- LineTo(hdc, star[i].x, star[i].y);
- }
- LineTo(hdc, star[0].x, star[0].y);
- DeleteObject(SelectObject(hdc, hOldPen));
- }
- EndPaint(hwnd, &ps);
- return 0;
-
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
-
- }
- return DefWindowProc(hwnd, message, wParam, lParam);
- }
复制代码 |
|