It is well known, that the win32 api CreateFont()-function does not guarantee the creation of the desired font. Unfortunatly it silently "fails" and returns the handle of a replacement font.
This is bad, because my application needs to know the success of CreateFont(). In order to check this I do the following, which works well:
// LOGFONT lf; ....
// lf.lfFaceName == "nameWanted" // assign my desired font name
HFONT hFnt = ::CreateFontIndirect(&lf);
HDC dc = ::CreateDC("DISPLAY",0,0,0);
HFONT oldfont = (HFONT)::SelectObject(dc, _h);
char nameFound[32];
::GetTextFace(dc,32,nameFound);
::SelectObject(dc, oldfont);
::DeleteDC(dc);
::DeleteObject(hFont);
const bool isOk = _stricmp("nameWanted", nameFound) == 0;
if (!isOk) {
// Font doesn't seem to be available.
// Handle this case
...
}
However this looks like overkill to me and I wonder, whether there is a direct way to check the success of CreateFont(). Did I miss something ?