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.