GDI多边形填充函数的一个使用心得

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

作者:朱金灿
来源:http://blog.csdn.net/clever101


       最近使用GDI,发现它的多边形填充函数Polygon (hdc, apt, iCount) ;会把多边形边界绘制出来。具体如下面代码:

  1. case WM_PAINT:  
  2.         {  
  3.         hdc = BeginPaint (hwnd, &ps) ;  
  4.         LOGBRUSH log_brush;  
  5.         log_brush.lbColor = RGB(255,0,0);  
  6.         log_brush.lbStyle = BS_SOLID;  
  7.         HBRUSH hNewBrush = ::CreateBrushIndirect(&log_brush);  
  8.         HBRUSH hOldBrush = SelectBrush(hdc,hNewBrush);  
  9.         POINT pt[4];  
  10.         pt[0].x = 10;  
  11.         pt[0].y = 10 ;  
  12.         pt[1].x = 10 ;  
  13.         pt[1].y = 100 ;  
  14.         pt[2].x = 100 ;  
  15.         pt[2].y = 100 ;  
  16.         pt[3].x = 100 ;  
  17.         pt[3].y = 10 ;  
  18.         Polygon(hdc,pt,4);  
  19.         log_brush.lbColor = RGB(0,255,0);  
  20.         HBRUSH hNewBrush2 = ::CreateBrushIndirect(&log_brush);  
  21.         SelectBrush(hdc,hNewBrush2);  
  22.         pt[0].x += 90;  
  23.         pt[0].y = 10 ;  
  24.         pt[1].x += 90 ;  
  25.         pt[1].y = 100 ;  
  26.         pt[2].x += 90 ;  
  27.         pt[2].y = 100 ;  
  28.         pt[3].x += 90 ;  
  29.         pt[3].y = 10 ;  
  30.         Polygon(hdc,pt,4);  
case WM_PAINT:  {  hdc = BeginPaint (hwnd, &ps) ;  LOGBRUSH log_brush;  log_brush.lbColor = RGB(255,0,0);        log_brush.lbStyle = BS_SOLID;  HBRUSH hNewBrush = ::CreateBrushIndirect(&log_brush);  HBRUSH hOldBrush = SelectBrush(hdc,hNewBrush);  POINT pt[4];  pt[0].x = 10;  pt[0].y = 10 ;  pt[1].x = 10 ;  pt[1].y = 100 ;  pt[2].x = 100 ;  pt[2].y = 100 ;  pt[3].x = 100 ;  pt[3].y = 10 ;  Polygon(hdc,pt,4);  log_brush.lbColor = RGB(0,255,0);  HBRUSH hNewBrush2 = ::CreateBrushIndirect(&log_brush);  SelectBrush(hdc,hNewBrush2);  pt[0].x += 90;  pt[0].y = 10 ;  pt[1].x += 90 ;  pt[1].y = 100 ;  pt[2].x += 90 ;  pt[2].y = 100 ;  pt[3].x += 90 ;  pt[3].y = 10 ;  Polygon(hdc,pt,4); 


效果图如下:


brush 1


       可以看出多边形的边界使用黑线绘制了出来,显然这是使用默认画笔绘制的。但是有些时候并不需要绘制边界。那么这时我们就要创建一个和画刷一样颜色的新画笔选进DC来代替系统默认画笔。将上面的代码修改如下:


  1. case WM_PAINT:  
  2.     {  
  3.     hdc = BeginPaint (hwnd, &ps) ;  
  4.     LOGBRUSH log_brush;  
  5.     log_brush.lbColor = RGB(255,0,0);  
  6.        log_brush.lbStyle = BS_SOLID;  
  7.     HBRUSH hNewBrush = ::CreateBrushIndirect(&log_brush);  
  8.     HBRUSH hOldBrush = SelectBrush(hdc,hNewBrush);  
  9.     LOGPEN log_pen;  
  10.     log_pen.lopnColor = RGB(255,0,0);  
  11.     log_pen.lopnStyle = PS_SOLID;  
  12.     log_pen.lopnWidth.x = 1;  
  13.     HPEN hNewPen = ::CreatePenIndirect(&log_pen);  
  14.     HPEN hOldPen = SelectPen(hdc,hNewPen);  
  15.     POINT pt[4];  
  16.     pt[0].x = 10;  
  17.     pt[0].y = 10 ;  
  18.     pt[1].x = 10 ;  
  19.     pt[1].y = 100 ;  
  20.     pt[2].x = 100 ;  
  21.     pt[2].y = 100 ;  
  22.     pt[3].x = 100 ;  
  23.     pt[3].y = 10 ;  
  24.     Polygon(hdc,pt,4);  
  25.     log_brush.lbColor = RGB(0,255,0);  
  26.     HBRUSH hNewBrush2 = ::CreateBrushIndirect(&log_brush);  
  27.     SelectBrush(hdc,hNewBrush2);  
  28.     log_pen.lopnColor = RGB(0,255,0);  
  29.     HPEN hNewPen2 = ::CreatePenIndirect(&log_pen);  
  30.     SelectPen(hdc,hNewPen2);  
  31.     pt[0].x += 90;  
  32.     pt[0].y = 10 ;  
  33.     pt[1].x += 90 ;  
  34.     pt[1].y = 100 ;  
  35.     pt[2].x += 90 ;  
  36.     pt[2].y = 100 ;  
  37.     pt[3].x += 90 ;  
  38.     pt[3].y = 10 ;  
  39.     Polygon(hdc,pt,4);  
  40.        SelectBrush(hdc,hOldBrush);  
  41.     SelectPen(hdc,hNewPen);  
  42.     EndPaint (hwnd, &ps) ;  
  43.     return 0 ;  
  44.     }  
 case WM_PAINT:  {  hdc = BeginPaint (hwnd, &ps) ;  LOGBRUSH log_brush;  log_brush.lbColor = RGB(255,0,0);        log_brush.lbStyle = BS_SOLID;  HBRUSH hNewBrush = ::CreateBrushIndirect(&log_brush);  HBRUSH hOldBrush = SelectBrush(hdc,hNewBrush);  LOGPEN log_pen;  log_pen.lopnColor = RGB(255,0,0);  log_pen.lopnStyle = PS_SOLID;  log_pen.lopnWidth.x = 1;  HPEN hNewPen = ::CreatePenIndirect(&log_pen);  HPEN hOldPen = SelectPen(hdc,hNewPen);  POINT pt[4];  pt[0].x = 10;  pt[0].y = 10 ;  pt[1].x = 10 ;  pt[1].y = 100 ;  pt[2].x = 100 ;  pt[2].y = 100 ;  pt[3].x = 100 ;  pt[3].y = 10 ;  Polygon(hdc,pt,4);  log_brush.lbColor = RGB(0,255,0);  HBRUSH hNewBrush2 = ::CreateBrushIndirect(&log_brush);  SelectBrush(hdc,hNewBrush2);  log_pen.lopnColor = RGB(0,255,0);  HPEN hNewPen2 = ::CreatePenIndirect(&log_pen);  SelectPen(hdc,hNewPen2);  pt[0].x += 90;  pt[0].y = 10 ;  pt[1].x += 90 ;  pt[1].y = 100 ;  pt[2].x += 90 ;  pt[2].y = 100 ;  pt[3].x += 90 ;  pt[3].y = 10 ;  Polygon(hdc,pt,4);        SelectBrush(hdc,hOldBrush);  SelectPen(hdc,hNewPen);  EndPaint (hwnd, &ps) ;  return 0 ;  } 


效果图如下:


brush 2








           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/gdruhv/article/details/84195702
今日推荐