CFont::operator HFONT

operator HFONT( ) const;

Return Value

The handle of the Windows GDI font object attached to CFont if successful; otherwise NULL.

Remarks

Use this operator to get the Windows GDI handle of the font attached to the CFont object.

Since this operator is automatically used for conversions from CFont to Fonts and Text, you can pass CFont objects to functions that expect HFONTs.

For more information about using graphic objects, see Graphic Objects in the Win32 SDK documentation.

Example

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

// Initialize a CFont object with the characteristics given 
// in a LOGFONT structure.
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));          // clear out structure
lf.lfHeight = 12;                         // request a 12-pixel-height font
strcpy(lf.lfFaceName, "Arial");           // request a face name "Arial"

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, "Hello", 5);
dc.SelectObject(def_font);

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

CFont OverviewClass MembersHierarchy Chart