GDI offers a variety of stock fonts that an application can retrieve and use. For many applications, the stock fonts provide all the functionality required for basic text output. To use stock fonts, an application specifies the type of font in the GetStockObject function. GetStockObject creates a handle to a logical font. When the application selects that handle into a device context, the font mapper uses the logical font to create a physical font. The application can select and use this physical font for text output.
GDI offers the following stock fonts:
Font | Description |
ANSI_FIXED_FONT | Specifies a fixed-pitch font based on the Windows character set. A Courier font is typically used. |
ANSI_VAR_FONT | Specifies a variable-pitch font based on the Windows character set. MS Sans Serif is typically used. |
DEVICE_DEFAULT_FONT | Specifies a font preferred by the given device. Because this font depends on how the GDI font mapper interprets font requests, the font may vary widely from device to device. |
OEM_FIXED_FONT | Specifies a fixed-pitch font based on an OEM character set. OEM character sets vary from system to system. For IBM computers and compatibles, the OEM font is based on the IBM PC character set. |
SYSTEM_FONT | Specifies the System font. This is a variable-pitch font based on the Windows character set, and is used by the 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. |
The following example retrieves a handle of the Windows variable stock font, selects it into a device context, and then writes a string using that font:
HFONT hfnt, hOldFont;
hfnt = GetStockObject(ANSI_VAR_FONT);
if (hOldFont = SelectObject(hdc, hfnt)) {
TextOut(hdc, 10, 50, "Sample ANSI_VAR_FONT text.", 26);
SelectObject(hdc, hOldFont);
}
If no other stock fonts are available, GetStockObject returns a handle to the System font (SYSTEM_FONT).
Applications that use the GetStockObject function to retrieve the handle of a logical font should work in MM_TEXT units. The logical font identified by the handle returned by GetStockObject may specify a height that does not match the height of the requested logical font when the application works in mapping modes other than MM_TEXT.