Chapter 8 GDI Orientation and Transformations Visual C++ and MFC Fundamentals
This method requires two value. The name of the font is specified with the lpszFaceName
value. If you do not want to specify a font, you can pass the argument as NULL. If you
have a CDC variable that can be used convert the value of the height to logical units. If
you do not have this value, set it to NULL.
Here is an example:
void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CFont font;
font.CreatePointFont(920, "Garamond");
CFont *pFont = pDC->SelectObject(&font);
pDC->TextOut(20, 18, "Christine", 9);
pDC->SelectObject(pFont);
font.DeleteObject();
}
To control the color applied when drawing the text, you can call the
CDC::SetTextColor() method. For example, the above name can be drawn in blue as
follows:
void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CFont font;
font.CreatePointFont(920, "Garamond");
CFont *pFont = pDC->SelectObject(&font);
pDC->SetTextColor(RGB(0, 125, 250));
pDC->TextOut(20, 18, "Christine", 9);
pDC->SelectObject(pFont);