CFont myFont; myFont.CreateFont(24, 0, 0, 0, FW_BOLD, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, _T("Georgia")); // Get the handle to the font object HFONT hFont = myFont.GetSafeHandle();
CFont* pFont = GetFont(); if(pFont != NULL) { // Get the handle to the font object HFONT hFont = pFont->GetSafeHandle(); }In this example, we retrieve a pointer to the current font object using GetFont(). Then we retrieve the handle to the font object using GetSafeHandle.