Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 9 Strings Visual C++ and MFC Fundamentals


pDC->SelectObject(brOld);
}

This would produce:

As you can see, we get only the the lower-right 3/4 portion of the square and the line is
pointing in the 3 to 6 quadrant of a clock.

Imagine that you want the origin (0, 0) to be positioned at the (220, 150) point. We saw
already that you can use the CDC::SetViewportOrg() (keep in mind that this member
function only changes the origin of the coordinate system; it does not influence the
orientation of the axes nor does it control the units or dimensions) method to specify the
origin. Here is an example (we are not specifying the mapping mode because MM_TEXT
can be used as the default):

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

CPen PenRed(PS_SOLID, 1, RGB(255, 0, 0));
CBrush BrushAqua(RGB(0, 255, 255));
CBrush *brOld;
CPen *pnOld;

pnOld = pDC->SelectObject(&PenRed);
brOld = pDC->SelectObject(&BrushAqua);

pDC->SetViewportOrg(220, 150);

// Draw a square with a red border and an aqua background
pDC->Rectangle(-100, -100, 100, 100);

CPen BluePen(PS_SOLID, 1, RGB(0, 0, 255));
pnOld = pDC->SelectObject(&BluePen);

// Diagonal line at 45 degrees starting at the origin (0, 0)
pDC->MoveTo(0, 0);
pDC->LineTo(120, 120);
Free download pdf