Polygon
用当前的笔绘制一个由两个或多个点(顶点)连接的多边形。
BOOL Polygon( LPPOINT lpPoints, int nCount );
lpPoints
指向一个指定多边形顶点的点。数组中的每一点都是一个点结构或一个CPoint对象。
nCount
指定数组中顶点的数量。
返回值
如果函数成功,则非零;否则0。
1 void CDCView::DrawPolygon(CDC* pDC) 2 { 3 // find the client area 4 CRect rect; 5 GetClientRect(rect); 6 7 // draw with a thick blue pen 8 CPen penBlue(PS_SOLID, 5, RGB(0, 0, 255)); 9 CPen* pOldPen = pDC->SelectObject(&penBlue); 10 11 // and a solid red brush 12 CBrush brushRed(RGB(255, 0, 0)); 13 CBrush* pOldBrush = pDC->SelectObject(&brushRed); 14 15 // Find the midpoints of the top, right, left, and bottom 16 // of the client area. They will be the vertices of our polygon. 17 CPoint pts[4]; 18 pts[0].x = rect.left + rect.Width()/2; 19 pts[0].y = rect.top; 20 21 pts[1].x = rect.right; 22 pts[1].y = rect.top + rect.Height()/2; 23 24 pts[2].x = pts[0].x; 25 pts[2].y = rect.bottom; 26 27 pts[3].x = rect.left; 28 pts[3].y = pts[1].y; 29 30 // Calling Polygon() on that array will draw three lines 31 // between the points, as well as an additional line to 32 // close the shape--from the last point to the first point 33 // we specified. 34 pDC->Polygon(pts, 4); 35 36 // Put back the old objects. 37 pDC->SelectObject(pOldPen); 38 pDC->SelectObject(pOldBrush); 39 }