Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


4 points, you must add three more. You can continue adding points by three to draw the
bézier curve. Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
CPoint Pt[] = {CPoint(20, 12), CPoint(88, 246),
CPoint(364, 192), CPoint(250, 48),
CPoint(175, 38), CPoint(388, 192), CPoint(145, 125) };

pDC->PolyBezier(Pt, 7);
}

PolyBezierTo(): The CDC::PolyBezier() method requires at least four points to draw its
curve. This is because it needs to know where to start drawing. Another way you can
control where the curve would start is by using the CDC::PolyBezierTo() method. Its
syntax is:

BOOL PolyBezierTo(const POINT* lpPoints, int nCount);

The PolyBezierTo() method draws a bézier curve. Its first argument is a pointer to an
array of POINT or CPoint values. This member function requires at least three points. It
starts drawing from the current line to the third point. If you do not specify the current
line, it would consider the origin (0, 0). The first and the second lines are used to control
the curve. The nCount argument is the number of points that would be considered. Here
is an example:

void CExoView::OnDraw(CDC* pDC)
{
CPoint Pt[] = { CPoint(320, 120), CPoint(88, 246), CPoint(364, 122) };

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