次の方法で共有


CFont::operator HFONT

CFont のオブジェクトにアタッチされているフォントの Windows GDI のハンドルを取得するには、この演算子を使用します。

operator HFONT( ) const;

戻り値

Windows GDI フォントのオブジェクト ハンドルは CFont に正常にアタッチされた; それ null

解説

この演算子が CFont から フォントやテキストへの変換に自動的に使用されるため、HFONT、.を受け取る関数への CFont のオブジェクトを渡すこともできます。

グラフィカル オブジェクトの使用方法の詳細については、Windows SDKの グラフィカル オブジェクト を参照してください。

使用例

// The code fragment shows the usage of CFont::operator HFONT.

// Initialize a CFont object with the characteristics given 
// in a LOGFONT structure.
LOGFONT lf;

// clear out structure
memset(&lf, 0, sizeof(LOGFONT)); 

// request a 12-pixel-height font
lf.lfHeight = 12;                

// request a face name "Arial"
_tcsncpy_s(lf.lfFaceName, LF_FACESIZE, _T("Arial"), 7);

CFont font1;
font1.CreateFontIndirect(&lf);  // create the font

// CFont::operator HFONT automatically converts font1 from 
// CFont* to HFONT.
CFont* font2 = CFont::FromHandle(font1);

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

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

必要条件

ヘッダー: afxwin.h

参照

関連項目

CFont クラス

階層図