读书人

急画多边形的有关问题

发布时间: 2012-03-04 11:13:33 作者: rapoo

急急急!求救!画多边形的问题
各位大哥大姐们,帮个忙,问个问题,就是用C++怎么画出多边形,谁能给我个代码吗,急需,我女朋友她明天要交,急死人了,大家快帮帮我谢谢

[解决办法]
CDC::Polygon
BOOL Polygon( LPPOINT lpPoints, int nCount );

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

lpPoints

Points to an array of points that specifies the vertices of the polygon. Each point in the array is a POINT structure or a CPoint object.

nCount

Specifies the number of vertices in the array.

Remarks

Draws a polygon consisting of two or more points (vertices) connected by lines, using the current pen. The system closes the polygon automatically, if necessary, by drawing a line from the last vertex to the first.

The current polygon-filling mode can be retrieved or set by using the GetPolyFillMode and SetPolyFillMode member functions.

Example

void CMyView::OnDraw(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);
}

读书人网 >C++

热点推荐