鱼C论坛

 找回密码
 立即注册
查看: 3091|回复: 4

[技术交流] 学完画刷自己写了一个画图小程序

[复制链接]
发表于 2016-4-12 11:21:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  2. {
  3.         HDC hdc;
  4.         PAINTSTRUCT ps;
  5.         POINT star[5];
  6.         POINT starcenter;
  7.         int r,i;
  8.         HBRUSH  hRedBrush,hOldBrush,hBrush,hBlueBrush;
  9.         HPEN hRedPen, hOldPen;

  10.         static int  cxClient, cyClient;
  11.         switch (message)
  12.         {
  13.         case WM_SIZE:
  14.                 cxClient = LOWORD(lParam);
  15.                 cyClient = HIWORD(lParam);
  16.                 return 0;
  17.         case WM_PAINT:
  18.                 hdc = BeginPaint(hwnd, &ps);
  19.                
  20.                 //确定五角星半径

  21.                 if (cxClient >= cyClient)
  22.                 {
  23.                         r = cyClient / 5;
  24.                 }
  25.                 else
  26.                 {
  27.                         r = cxClient / 5;
  28.                 }
  29.                
  30.                 //绘制中心五角心
  31.                
  32.                 starcenter.x = cxClient / 2;
  33.                 starcenter.y = cyClient / 2;

  34.                 //左上点

  35.                 star[0].x = starcenter.x - (int)(r*sin(2 * PI / 5));
  36.                 star[0].y = starcenter.y - (int)(r*cos(2 * PI / 5));

  37.                 //右上点

  38.                 star[1].x = starcenter.x + (int)(r*sin(2 * PI / 5));
  39.                 star[1].y = starcenter.y - (int)(r*cos(2 * PI / 5));

  40.                 //左下点
  41.                 star[2].x = starcenter.x - (int)(r*sin(PI / 5));
  42.                 star[2].y = starcenter.y + (int)(r*cos(PI / 5));

  43.                 //顶点

  44.                 star[3].x = starcenter.x;
  45.                 star[3].y = starcenter.y - r;


  46.                 //右下点

  47.                 star[4].x = starcenter.x + (int)(r*sin(PI / 5));
  48.                 star[4].y = starcenter.y + (int)(r*cos(PI / 5));

  49.                         if (cxClient >= cyClient)
  50.                         {
  51.                                 //画外层红圈
  52.                                 hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
  53.                                 hOldBrush = SelectObject(hdc, hRedBrush);
  54.                                 Ellipse(hdc, (cxClient - cyClient) / 2, 0, (cxClient + cyClient) / 2, cyClient);
  55.                                 SelectObject(hdc, hOldBrush);

  56.                                 //画内存白圈
  57.                                 hBrush = GetStockObject(DC_BRUSH);
  58.                                 hOldBrush = SelectObject(hdc, hBrush);
  59.                                 Ellipse(hdc, (cxClient - cyClient) / 2 + cyClient / 10, cyClient / 10, (cxClient + cyClient) / 2 - cyClient / 10, cyClient * 9 / 10);
  60.                                 SelectObject(hdc, hOldBrush);

  61.                                 //画最内层红圈
  62.                                 hOldBrush = SelectObject(hdc, hRedBrush);
  63.                                 Ellipse(hdc, (cxClient - cyClient) / 2 + cyClient / 5, cyClient / 5, (cxClient + cyClient) / 2 - cyClient / 5, cyClient * 4 / 5);
  64.                                 SelectObject(hdc, hRedBrush);

  65.                                 //画五角星蓝色背景
  66.                                 hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
  67.                                 hOldBrush = SelectObject(hdc, hBlueBrush);
  68.                                 Ellipse(hdc, (cxClient - cyClient) / 2 + cyClient * 3 / 10, cyClient * 3 / 10, (cxClient + cyClient) / 2 - cyClient * 3 / 10, cyClient * 7 / 10);
  69.                                 DeleteObject(SelectObject(hdc, hOldBrush));

  70.                                 //画中心五角星
  71.                                 SelectObject(hdc, hRedBrush);
  72.                                 SetPolyFillMode(hdc,WINDING);
  73.                                 Polygon(hdc, star, 5);
  74.                                 DeleteObject(SelectObject(hdc, hRedBrush));

  75.                                 //覆盖五角星内部多余的线

  76.                                 hRedPen = CreatePen(PS_SOLID, 0, RGB(255, 0, 0));
  77.                                 hOldPen = SelectObject(hdc, hRedPen);
  78.                                 MoveToEx(hdc, star[0].x, star[0].y, NULL);
  79.                                 for (i = 1; i < 5; i++)
  80.                                 {
  81.                                         LineTo(hdc, star[i].x, star[i].y);
  82.                                 }
  83.                                 LineTo(hdc, star[0].x, star[0].y);
  84.                                 DeleteObject(SelectObject(hdc, hOldPen));
  85.                         }
  86.                         else
  87.                         {
  88.                                 hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
  89.                                 hOldBrush = SelectObject(hdc, hRedBrush);
  90.                                 Ellipse(hdc, 0, (cyClient - cxClient) / 2, cxClient, (cyClient + cxClient) / 2);
  91.                                 SelectObject(hdc, hRedBrush);

  92.                                 hBrush = GetStockObject(DC_BRUSH);
  93.                                 hOldBrush = SelectObject(hdc, hBrush);
  94.                                 Ellipse(hdc, cxClient / 10, (cyClient - cxClient) / 2 + cxClient / 10, cxClient - cxClient / 10, (cyClient + cxClient) / 2 - cxClient / 10);
  95.                                 SelectObject(hdc, hOldBrush);

  96.                                 hOldBrush = SelectObject(hdc, hRedBrush);
  97.                                 Ellipse(hdc, cxClient / 5, (cyClient - cxClient) / 2 + cxClient / 5, cxClient - cxClient * 2 / 10, (cyClient + cxClient) / 2 - cxClient * 2 / 10);
  98.                                 SelectObject(hdc, hOldBrush);

  99.                                 hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
  100.                                 hOldBrush = SelectObject(hdc, hBlueBrush);
  101.                                 Ellipse(hdc, cxClient * 3 / 10, (cyClient - cxClient) / 2 + cxClient * 3 / 10, cxClient - cxClient * 3 / 10, (cyClient + cxClient) / 2 - cxClient * 3 / 10);
  102.                                 DeleteObject(SelectObject(hdc, hOldBrush));

  103.                                 hOldBrush = SelectObject(hdc, hRedBrush);
  104.                                 SetPolyFillMode(hdc, WINDING);
  105.                                 Polygon(hdc, star, 5);
  106.                                 DeleteObject(SelectObject(hdc, hOldBrush));

  107.                                 hRedPen = CreatePen(PS_SOLID, 0, RGB(255, 0, 0));
  108.                                 hOldPen = SelectObject(hdc, hRedPen);
  109.                                 MoveToEx(hdc, star[0].x, star[0].y, NULL);
  110.                                 for (i = 1; i < 5; i++)
  111.                                 {
  112.                                         LineTo(hdc, star[i].x, star[i].y);
  113.                                 }
  114.                                 LineTo(hdc, star[0].x, star[0].y);
  115.                                 DeleteObject(SelectObject(hdc, hOldPen));

  116.                         }
  117.                 EndPaint(hwnd, &ps);
  118.                 return 0;
  119.                
  120.         case WM_DESTROY:
  121.                 PostQuitMessage(0);
  122.                 return 0;

  123.        

  124.         }
  125.         return DefWindowProc(hwnd, message, wParam, lParam);
  126. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-4-12 11:31:01 | 显示全部楼层
能再给一个效果图么
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-4-13 13:06:49 | 显示全部楼层
1111
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-5-30 10:29:40 | 显示全部楼层
大牛  感谢分享
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-7-18 17:35:40 | 显示全部楼层
运行不起来,一直报错
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 21:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表