Visual C++ and MFC Fundamentals Chapter 9: Strings
pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetViewportOrg(220, 150);
pDC->SetWindowExt(640, 640);
// 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);
pDC->SelectObject(pnOld);
pDC->SelectObject(brOld);
}
After calling the SetWindowExt() member function, you should call the
SetViewportExt() method. Its job is to specify the horizontal and vertical units of the
device context being used. It comes in two versions with the following syntaxes:
CSize SetViewportExt(int cx, int cy);
CSize SetViewportExt(SIZE size);
To use the first version of this function, you must provide the units of device conversion
as cx for the horizontal axis and as cy for the vertical axis.
If you know the size as a width/height combination of the device unit conversion, you can
use the second version of the function and supply this size argument.
Here is an example:
void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPen PenRed(PS_SOLID, 1, RGB(255, 0, 0));