Installing and Using Fonts

Call the AddFontResource function to load a font from a font resource file. When you finish using an installed font, call the RemoveFontResource function to remove the font. Whenever you add or delete a font resource, you should call the SendMessage function to send a WM_FONTCHANGE message to all top-level windows in the system. This message notifies other applications that an application has modified the internal font table by adding or removing a font. You do not need to call 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. This process is called font mapping.

    To use a font

  1. Call the EnumFontFamilies function to build a list of the available fonts. This is especially useful when you want to determine available fonts 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 loads 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 particular 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 an appropriate 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 standard logical fonts. You can use the GetStockObject function to obtain a standard font. The following table shows the standard font values.

Value
Description
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.
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 installed.