Поделиться через


CFont::CreateFontIndirect

Initializes a CFont object with the characteristics given in a LOGFONT structure pointed to by lpLogFont.

BOOL CreateFontIndirect(
   const LOGFONT* lpLogFont 
);

Параметры

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

Возвращаемое значение

Nonzero if successful; otherwise 0.

Заметки

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's font mapper attempts to match the logical font with an existing physical font. If it fails to find an exact match for the logical font, it provides an alternative whose characteristics match as many of the requested characteristics as possible.

When you finish with the CFont object created by the CreateFontIndirect function, first select the font out of the device context, then delete the CFont object.

Пример

// 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();

Требования

Header: afxwin.h

См. также

Основные понятия

CFont Class

CFont Members

Hierarchy Chart

CFont::CreateFont

CFont::CreatePointFontIndirect

CDC::SelectObject

CGdiObject::DeleteObject

CreateFontIndirect