Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 9: Strings


In the same way, you can draw any geometric or non-geometric figure you want, using
one of the CDC methods or creating functions of your choice. For example, the following
code draws a vertical and a horizontal lines that cross each other in the center middle of
the view:

void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CPen PenBlue;
CPen *pOld;

PenBlue.CreatePen(PS_SOLID, 1, RGB(0, 12, 255));
pOld = pDC->SelectObject(&PenBlue);
pDC->Ellipse(-100, -100, 100, 100);

CPen PenBlack;
PenBlack.CreatePen(PS_SOLID, 1, BLACK_PEN);
pOld = pDC->SelectObject(&PenBlack);

pDC->MoveTo(220, 0);
pDC->LineTo(220, 370);
pDC->MoveTo(0, 160);
pDC->LineTo(460, 160);

pDC->SelectObject(pOld);
}
Free download pdf