Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


We have mentioned that the CDC::MoveTo() method is used to set the starting position
of a line. When using LineTo(), the line would start from the MoveTo() point to the
LineTo() end. As long as you do not call MoveTo(), any subsequent call to LineTo()
would draw a line from the previous LineTo() to the new LineTo() point. You can use
this property of the LineTo() method to draw various lines. Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
pDC->MoveTo(60, 20);
pDC->LineTo(60, 122);
pDC->LineTo(264, 122);
pDC->LineTo(60, 20);
}

Practical Learning: Drawing Lines


Access the OnPaint event of your view class and implement it as follows:
void CView1View::OnPaint()
{
CPaintDC dc(this); // device context for painting

Free download pdf