Share via


CFont::CreateFontIndirect

初始化與 LOGFONT結構指定的 CFont 特性來建立物件。

BOOL CreateFontIndirect(
   const LOGFONT* lpLogFont 
);

參數

  • lpLogFont
    LOGFONT 的點結構定義邏輯字型的特性。

傳回值

如果不是零,則成功,則為 0。

備註

字型接著選取做為目前字型對於所有裝置。

這個字型會在 LOGFONT 結構指定的特性。 您可以使用 CDC::SelectObject 成員函式時,當選取字型, GDI 字型對應器會嘗試比對邏輯字型與現有的實體字型。 如果字型對應器會找不到邏輯字型的完全相符,並提供特性符合許多要求的特性盡可能的替代字型。

當您不再需要 CreateFontIndirect 函式時所建立的 CFont 物件,請使用 CDC::SelectObject 選取不同的字型的裝置內容,然後刪除不再需要的 CFont 物件。

範例

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

需求

標題: afxwin.h

請參閱

參考

CFont 類別

階層架構圖

CFont::CreateFont

CFont::CreatePointFontIndirect

CDC::SelectObject

CGdiObject::DeleteObject

CreateFontIndirect

LOGFONT