windows_programming_notes.nbk: Home | Index | Next Page: CreatePen | Previous Page: CreateFile


 CreateFont

The CreateFont function creates a logical font with the specified characteristics. The logical font can subsequently be selected as the font for any device.

    HFONT CreateFont(
      int       nHeight,            // height of font
      int       nWidth,             // average character width
      int       nEscapement,        // angle of escapement
      int       nOrientation,       // base-line orientation angle
      int       fnWeight,           // font weight
      DWORD     fdwItalic,          // italic attribute option
      DWORD     fdwUnderline,       // underline attribute option
      DWORD     fdwStrikeOut,       // strikeout attribute option
      DWORD     fdwCharSet,         // character set identifier
      DWORD     fdwOutputPrecision, // output precision
      DWORD     fdwClipPrecision,   // clipping precision
      DWORD     fdwQuality,         // output quality
      DWORD     fdwPitchAndFamily,  // pitch and family
      LPCTSTR   lpszFace            // typeface name
    );

Parameters

OUT_TT_ONLY_PRECIS Instructs the font mapper to choose from only TrueType fonts. If there are no TrueType fonts installed in the system, the font mapper returns to default behavior. OUT_TT_PRECIS Instructs the font mapper to choose a TrueType font when the system contains multiple fonts with the same name.

For more information about the orientation of coordinate systems, see the description of the nOrientation parameter

CLIP_MASK Not used. CLIP_DFA_OVERRIDE Windows 2000: Turns off font association for the font. This is identical to CLIP_DFA_DISABLE, but it can have problems in some situations; the recommended flag to use is CLIP_DFA_DISABLE. CLIP_STROKE_PRECIS Not used by the font mapper, but is returned when raster, vector, or TrueType fonts are enumerated. Windows NT/2000/XP: For compatibility, this value is always returned when enumerating fonts.

CLIP_TT_ALWAYS Not used.

Return Values

If the function succeeds, the return value is a handle to a logical font.

If the function fails, the return value is NULL.

Windows NT/2000/XP: To get extended error information, call GetLastError.

Remarks

When you no longer need the font, call the DeleteObject function to delete it.

To help protect the copyrights of vendors who provide fonts for Windows, applications should always report the exact name of a selected font. Because available fonts can vary from system to system, do not assume that the selected font is always the same as the requested font. For example, if you request a font named Palatino, but no such font is available on the system, the font mapper will substitute a font that has similar attributes but a different name. Always report the name of the selected font to the user.

To get the appropriate font on different language versions of the OS, call EnumFontFamiliesEx with the desired font characteristics in the LOGFONT structure, then retrieve the appropriate typeface name and create the font using CreateFont or CreateFontIndirect.

Windows 95/98/Me, Windows NT 4.0: The fonts for many East Asian languages have two typeface names: an English name and a localized name. CreateFont, CreateFontIndirect and CreateFontIndirectEx take the localized typeface name on a system locale that matches the language, but they take the English typeface name on all other system locales. The best method is to try one name and, on failure, try the other. Note that EnumFonts, EnumFontFamilies, and EnumFontFamiliesEx return the English typeface name if the system locale does not match the language of the font.

Windows 2000/XP: The font mapper for CreateFont, CreateFontIndirect, and CreateFontIndirectEx recognizes both the English and the localized typeface name, regardless of locale.

Windows XP: The following situations do not support ClearType antialiasing:

Text rendered on a printer. A display set for 256 colors or less. Text rendered to a terminal server client. The font is not a TrueType font or an OpenType font with TrueType outlines. For example, the following do not support ClearType antialiasing: Type 1 fonts, Postscript OpenType fonts without TrueType outlines, bitmap fonts, vector fonts, and device fonts . The font has tuned embedded bitmaps, only for the font sizes that contain the embedded bitmaps. For example, this occurs commonly in East Asian fonts. Windows 95/98/Me: CreateFontW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Requirements


windows_programming_notes.nbk: Home | Index | Next Page: CreatePen | Previous Page: CreateFile


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time