Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


The beginning and the end are two distinct points that can be either POINT, CPoint, or a
mix of a POINT and a CPoint values. In real life, before drawing, you should define
where you would start. To help with this, the CDC class provides the MoveTo() method.
It comes in two versions that are:

CPoint MoveTo(int x, int y);
CPoint MoveTo(POINT point);

The origin of a drawing is specified as a CPoint value. You can provide its horizontal and
vertical measures as x and y or you can pass it as a POINT or a CPoint value.

To end the line, you use the CDC::LineTo() method. It comes it two versions declared as
follows:

BOOL LineTo(int x, int y);
BOOL LineTo(POINT point);

The end of a line can be defined by its horizontal (x) and its vertical measures (y). It can
also be provided as a POINT or a CPoint value. The last point of a line is not part of the
line. The line ends just before reaching that point.

Here is an example that draws a line starting at a point defined as (10, 22) coordinates
and ending at (155, 64):

void CExoView::OnDraw(CDC* pDC)
{
pDC->MoveTo(10, 22);
pDC->LineTo(155, 64);
}
Free download pdf