Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 7: GDI Accessories and Tools Visual C++ and MFC Fundamentals


dc.LineTo(PtLine[5]);
dc.LineTo(PtLine[6]);
dc.LineTo(PtLine[7]);
dc.LineTo(PtLine[8]);


dc.Polygon(Bedroom1, 4);
dc.Polygon(Closets, 4);
dc.Polygon(Bedroom2, 4);
// Do not call CView::OnPaint() for painting messages
}


Test the application and return to MSVC


6.3.5 Multiple Polygons................................................................................


If you want to draw multiple polygons, you can use the CDC::PolyPolygon() method
whose syntax is:

BOOL PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount);

Like the Polygon() method, the lpPoints argument is an array of POINT or CPoint values.
The PolyPolygon() method needs to know the number of polygons you would be
drawing. Each polygon uses the points of the lpPoints values but when creating the array
of points, the values must be incremental. This means that PolyPolygon() will not
randomly access the values of lpPoints. Each polygon has its own set of points.

Unlike Polygon(), the nCount argument of PolyPolygon() is the number of polygons you
want to draw and not the number of points.

The lpPolyCounts argument is an array or integers. Each member of this array specifies
the number of vertices (lines) that its polygon will have..

Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
CPoint Pt[12];
int lpPts[] = { 3, 3, 3, 3 };

// Top Triangle
Pt[0] = CPoint(125, 10);
Pt[1] = CPoint( 95, 70);
Pt[2] = CPoint(155, 70);

// Left Triangle
Pt[3] = CPoint( 80, 80);
Pt[4] = CPoint( 20, 110);
Pt[5] = CPoint( 80, 140);

// Bottom Triangle
Pt[6] = CPoint( 95, 155);
Pt[7] = CPoint(125, 215);
Pt[8] = CPoint(155, 155);

// Right Triangle
Pt[9] = CPoint(170, 80);
Free download pdf