Share via


CFont::CreateFontIndirect

LOGFONT 構造体で指定された特性で CFont オブジェクトを初期化します。

BOOL CreateFontIndirect(
   const LOGFONT* lpLogFont 
);

パラメーター

  • lpLogFont
    論理フォントの特性を定義した LOGFONT 構造体へのポインター。

戻り値

正常終了した場合は 0 以外を返します。それ以外の場合は 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

その他の技術情報

CFont のメンバー