Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 9: Strings


8.2.2 Unit and Coordinate Systems Options.............................................


The mapping modes we have used so far allowed us to select the orientation of the axes,
especially the y axis. Nevertheless, we could not influence any conversion unit for the
dimensions we specified on our drawings. This is because each one of these mapping
modes (MM_TEXT, MM_HIENGLISH, MM_LOENGLISH, MM_HIMETRIC,
MM_LOMETRIC, and MM_TWIPS) has a fixed set of attributes such as the orientation
of its axes and the conversion used on the provided dimensions.

Consider the following OnDraw() method. It draws a 200x200 pixels square with a red
border and an aqua background. The square starts at 100x100 pixels on the negative sides
of both axes and it continues 100x100 pixels on the positive sides of both axes. For better
illustration, the event also draws a diagonal line at 45º starting at the origin (0, 0):

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);

// 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(200, 200);

pDC->SelectObject(pnOld);
Free download pdf