Case in point:
void CMainWindow::OnPaint ()
{
CRect rect;
GetClientRect (&rect);
CPaintDC dc (this);
dc.SetViewportOrg (rect.Width () / 2, rect.Height () / 2);
dc.SetBkMode (TRANSPARENT);
for (int i=0; i<3600; i+=150) {
LOGFONT lf;
::ZeroMemory (&lf, sizeof (lf));
lf.lfHeight = 160;
lf.lfWeight = FW_BOLD;
lf.lfEscapement = i;
lf.lfOrientation = i;
::lstrcpy (lf.lfFaceName, _T ("Arial"));
CFont font;
font.CreatePointFontIndirect (&lf);
CFont* pOldFont = dc.SelectObject (&font);
dc.TextOut (0, 0, CString (_T (" Hello, MFC")));
//WHY THIS LINE?
dc.SelectObject (pOldFont);
}
}
The code prints " Hello, MFC" in a circle around the origin (which is moved to the center of the window).

Why is that CFont pointer created and then the dc selects it as the font? Is that just good programming practice or does this app actually need it?
I've seen similar code on the web doing this with Bitmaps and other device context objects. What's the purpose?
When I remove that last line of the code, nothing changes. Thanks in advance for the help.
Device Context:
At any time, there is exactly one graphic object selected into a device context. Since the system stores a set of default objects into a device context when it is created, an application must retain that state, when the device context is handed back to the system for cleanup. That is what
is responsible for.
This requirement is documented under SelectObject:
Note: This is not related to MFC, but rather the Windows GDI. MFC merely implements an automatic resource management wrapper. State management still requires explicit code.