Condividi tramite


CFont::CreateFontIndirect

Initializes a CFont object with the characteristics given in a LOGFONTstructure.

BOOL CreateFontIndirect( 
   const LOGFONT* lpLogFont  
);

Parameters

  • lpLogFont
    Points to a LOGFONT structure that defines the characteristics of the logical font.

Return Value

Nonzero if successful; otherwise 0.

Remarks

The font can subsequently be selected as the current font for any device.

This font has the characteristics specified in the LOGFONT structure. When the font is selected by using the CDC::SelectObject member function, the GDI font mapper attempts to match the logical font with an existing physical font. If the font mapper fails to find an exact match for the logical font, it provides an alternative font whose characteristics match as many of the requested characteristics as possible.

When you no longer need the CFont object created by the CreateFontIndirect function, use CDC::SelectObject to select a different font into the device context, then delete the CFont object that is no longer needed.

Example

// The code fragment shows how to create a font object, 
// select the font object into a DC (device context) for text 
// drawing, and finally delete the font object. 

// Initializes a CFont object with the characteristics given  
// in a LOGFONT structure.
CFont font;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));       // zero out structure
lf.lfHeight = 12;                      // request a 12-pixel-height font
_tcsncpy_s(lf.lfFaceName, LF_FACESIZE, 
   _T("Arial"), 7);                    // request a face name "Arial"
VERIFY(font.CreateFontIndirect(&lf));  // create the font 

// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, _T("Hello"), 5);
dc.SelectObject(def_font);

// Done with the font. Delete the font object.
font.DeleteObject();

Requirements

Header: afxwin.h

See Also

Reference

CFont Class

Hierarchy Chart

CFont::CreateFont

CFont::CreatePointFontIndirect

CDC::SelectObject

CGdiObject::DeleteObject

CreateFontIndirect

LOGFONT