1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Use of CreateFontIndirect

Discussion in 'Win32' started by watson, Jul 24, 2010.

  1. watson

    watson New Member

    Jul 24, 2010
    Likes Received:
    Trophy Points:
    Say, if I want to create a font:
    LOGFONT lf = {0};
    lf.lfHeight = 12;
    lf.lfWeight = FW_THIN;
    VERIFY(StringCchCopy(lf.lfFaceName, sizeof(lf.lfFaceName) / sizeof(lf.lfFaceName[0]), _T("Calibri")) == S_OK);
    HFONT hFont = CreateFontIndirect(&lf);
    	//Font created OK
    If I specify pretty much any name as lfFaceName CreateFontIndirect() returns a handle anyway. My understanding was that it will return NULL if it can't create that exact font. Am I correct on that one?

    PS. I'm running this code on Windows 7, so maybe they added some fail-safe mechanism for it already...

    PS 2. I'm kind of confused over this statement:

    I do not have a machine with East Asian languages, nor that I can speak those languages. What would be the correct way to create a font on those machines?

    The strategy I thought of is to try to create a font that I want, say, "Calibri", and if it can't be created (if it's not installed), try some basic font, like "Arial" for instance. But again, CreateFontIndirect seems to return a handle for any font type name I specify for it.

Share This Page