Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


is that a polyline does not start where the previous line ended. Each polyline has its own
beginning and its own ending point.

Unlike Polyline(), here, the nCount argument is actually the number of shapes you want
to draw and not the number of points (remember that each polyline "knows" or controls
its beginning and end).

The lpPolyPoints argument is an array or positive integers (unsigned long). Each member
of this array specifies the number of vertices (lines) that its corresponding polyline will
have. For example, imagine you want to draw M, followed by L, followed by Z. The
letter M has 4 lines but you need 5 points to draw it. The letter L has 2 lines and you need
3 points to draw it. The letter Z has 3 lines so 4 points are necessary to draw it. You can
store this combination of lines in an array defined as { 5, 3, 4 }.

Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
CPoint Pt[15];
DWORD lpPts[] = { 4, 4, 7 };

// Left Triangle
Pt[0] = Pt[3] = CPoint(50, 20);
Pt[1] = CPoint(20, 60);
Pt[2] = CPoint(80, 60);

// Second Triangle
Pt[4] = Pt[7] = CPoint(70, 20);
Pt[5] = CPoint(100, 60);
Pt[6] = CPoint(130, 20);

// Hexagon
Pt[8] = Pt[14] = CPoint(145, 20);
Pt[9] = CPoint(130, 40);
Pt[10] = CPoint(145, 60);
Pt[11] = CPoint(165, 60);
Pt[12] = CPoint(180, 40);
Pt[13] = CPoint(165, 20);

pDC->PolyPolyline(Pt, lpPts, 3);
}
Free download pdf