Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 8 GDI Orientation and Transformations


The nQuality specifies how the function will attempt to match the font's characteristics.
The possible values are DEFAULT_QUALITY, PROOF_QUALITY, and
DRAFT_QUALITY.
The nPitchAndFamily specifies the category of the font used. It combines the pitch and
the family the intended font belongs to. The pitch can be specified with
DEFAULT_PITCH, VARIABLE_PITCH, or FIXED_PITCH. The pitch is combined
using the bitwise OR operator with one of the following values:

Value Description
FF_DECORATIVE Used for a decorative or fancy font
FF_DONTCARE Let the compiler specify
FF_MODERN Modern fonts that have a constant width
FF_ROMAN Serif fonts with variable width
FF_SCRIPT Script-like fonts
FF_SWISS Sans serif fonts with variable width

The lpszFacename is the name of the font used.

Once you have created a font, you can select it into the device context and use it it for
example to draw text.

After using a font, you should delete it to reclaim the memory space its variable was
using. This is done by calling the CGdiObject::DeleteObject() method.

Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
CFont font;

font.CreateFont(46, 28, 215, 0,
FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_ROMAN, "Times New Roman");

CFont *pFont = pDC->SelectObject(&font);
pDC->TextOut(20, 128, "Euzhan Palcy", 12);

pDC->SelectObject(pFont);
font.DeleteObject();
}
Free download pdf