VC 绘图技巧--自定义形状图形

时间:2023-02-02 15:17:47

自定义形状图形,定义几个点围城的图形,然后进行描边和填充:

  1. if (m_memDC.m_hDC!=NULL)
  2. {
  3. CPoint point[4];
  4. point[0].x=nLeft+(int)(0.1*m_nWidth);
  5. point[0].y=m_nYmargin;
  6. point[1].x=nLeft+(int)(0.9*m_nWidth);
  7. point[1].y=m_nYmargin;
  8. point[2].x=nLeft+(int)(0.7*m_nWidth);
  9. point[2].y=(int)(0.2*m_nWidth)+m_nYmargin;
  10. point[3].x=nLeft+(int)(0.3*m_nWidth);
  11. point[3].y=(int)(0.2*m_nWidth)+m_nYmargin;
  12. CBrush br(m_crText);  //文字颜色
  13. CRgn rgn;
  14. rgn.CreatePolygonRgn(point,4,ALTERNATE);  //由所有点围城的不规则矩形
  15. m_memDC.FillRgn(&rgn,&br);   //填充该段
  16. br.DeleteObject();  //释放画刷
  17. rgn.DeleteObject();
  18. m_memDC.MoveTo(point[0]);
  19. m_memDC.LineTo(point[1]);
  20. m_memDC.MoveTo(point[1]);
  21. m_memDC.LineTo(point[2]);
  22. m_memDC.MoveTo(point[2]);
  23. m_memDC.LineTo(point[3]);
  24. m_memDC.MoveTo(point[3]);
  25. m_memDC.LineTo(point[0]);
  26. }