Using Fonts

Use the AddFontResource function to load a font from a font-resource file. When you finish using an installed font, use the RemoveFontResource function to remove it. Whenever you add or delete a font resources, you should use the SendMessage function to send a WM_FONTCHANGE message to all top-level windows in the system. This message notifies other applications that the an application has added or removed a font to the internal font table. You do not need to use AddFontResources to create or realize system fonts.

There are two stages to selecting a font. In the first stage, you specify the ideal font you would like to use. This theoretical font is called a logical font. In the second stage, an internal algorithm finds the physical font that is the closest match to your specified logical font. A physical font is a font stored on the device or in the operating system. The process of finding the physical font that most closely matches a specified logical font is called font mapping.

    To use a font
  1. Use the EnumFontFamilies function to list the available fonts. This is especially useful when you want to determine which fonts are available from a specified font family or typeface.
  2. Use the values returned by the font enumeration function to initialize the members of a LOGFONT structure.
  3. Create the logical font by calling the CreateFontIndirect function and passing it a pointer to the initialized LOGFONT structure.
  4. Select the logical font into the current device context with the SelectObject function.

When you call SelectObject, Windows CE will load the physical font that most closely matches the logical font specified in the LOGFONT structure.

When initializing the members of the LOGFONT structure, be sure that the lfCharSet member specifies a specific character set. This member is used in the font mapping process and the results will be inconsistent if this member is not initialized correctly. If you specify a typeface name in the lfFaceName member of the LOGFONT structure, be sure that the lfCharSet value contains a matching value.

Windows CE keeps a table containing all the fonts available for application use. When you call CreateFontIndirect, Windows CE chooses a font from this table.

Windows CE provides six stock logical fonts. You can use the GetStockObject function to obtain a stock font. The stock font values are described in the following table.

Value Meaning
ANSI_FIXED_FONT Specifies a monospace font based on the Windows character set, usually represented by a Courier font.
ANSI_VAR_FONT Specifies a proportional font based on the Windows character set, usually represented by the MS Sans Serif font.
DEVICE_DEFAULT_FONT Specifies the preferred font for the specified device, usually represented by the System font for display devices.
OEM_FIXED_FONT Specifies a monospace font based on an OEM character set. For IBM computers and compatibles, the OEM font is based on the IBM desktop computer character set.
SYSTEM_FONT Specifies the System font. This is a proportional font based on the Windows character set, and is used by the operating system to display window titles, menu names, and text in dialog boxes. The System font is always available. Other fonts are available only if they have been installed.
SYSTEM_FIXED_FONT Specifies a monospace font compatible with the System font in Windows versions earlier than 3.0.