CDC::Polygon

绘制由两个或多个多边形的点(顶点)连接由行,请使用将向当前钢笔。

BOOL Polygon(
   LPPOINT lpPoints,
   int nCount 
);

参数

  • lpPoints
    指向指定多边形的顶点的一系列点。每一个数组点是 POINT 结构或 CPoint 对象。

  • nCount
    该数组指定顶点的数目。

返回值

非零,如果函数运行成功;否则为0。

备注

该系统通过绘制线条如果需要,自动闭合多边形,从最后一个顶点到第一。

使用 GetPolyFillModeSetPolyFillMode 成员函数,当前多边形加载模式中检索或设置。

示例

void CDCView::DrawPolygon(CDC* pDC)
{
   // find the client area
   CRect rect;
   GetClientRect(rect);

   // draw with a thick blue pen
   CPen penBlue(PS_SOLID, 5, RGB(0, 0, 255));
   CPen* pOldPen = pDC->SelectObject(&penBlue);

   // and a solid red brush
   CBrush brushRed(RGB(255, 0, 0));
   CBrush* pOldBrush = pDC->SelectObject(&brushRed);

   // Find the midpoints of the top, right, left, and bottom
   // of the client area. They will be the vertices of our polygon.
   CPoint pts[4];
   pts[0].x = rect.left + rect.Width()/2;
   pts[0].y = rect.top;

   pts[1].x = rect.right;
   pts[1].y = rect.top + rect.Height()/2;

   pts[2].x = pts[0].x;
   pts[2].y = rect.bottom;

   pts[3].x = rect.left;
   pts[3].y = pts[1].y;

   // Calling Polygon() on that array will draw three lines
   // between the points, as well as an additional line to
   // close the shape--from the last point to the first point
   // we specified.
   pDC->Polygon(pts, 4);

   // Put back the old objects.
   pDC->SelectObject(pOldPen);
   pDC->SelectObject(pOldBrush);
}

要求

Header: afxwin.h

请参见

参考

CDC 类

层次结构图

CDC::GetPolyFillMode

CDC::Polyline

CDC::PolyPolygon

CDC::SetPolyFillMode

CPoint选件类

Polygon