The Font dialog box lets the user choose attributes for a logical font, such as typeface name, style (bold, italic, or regular), point size, effects (underline, strikeout, and text color), and a script (or character set).
You create and display a Font dialog box by initializing a
The following illustration shows a typical Font dialog box.

If the user clicks the OK button, ChooseFont returns TRUE and
sets the members of the
If the user cancels the Font dialog box or an error occurs, ChooseFont
returns FALSE and the contents of the LOGFONT structure are not
defined. You can determine the cause of an error by using the
The following topics are discussed in this section.
Before calling ChooseFont, the Flags member of the CHOOSEFONT structure must specify CF_SCREENFONTS, CF_PRINTERFONTS, or CF_BOTH, to indicate whether the dialog box should list screen fonts, printer fonts, or both. If you specify CF_PRINTERFONTS or CF_BOTH, the hDC member of the CHOOSEFONT structure must specify a handle to a device context for the printer.
You can use the Flags member to enable or disable some of the dialog box controls, and you can use the Flags member in conjunction with other CHOOSEFONT members to control the initial values of some controls.
To display the controls that allow the user to select strikeout, underline, and color options
To specify the initial values of the Font, Font Style, Size, Strikeout, and Underline dialog box controls
To initialize the Font Style control to a specified style name
To display the Apply button
To display the Help button
To restrict the fonts the dialog box displays
To restrict the typeface names, styles, and point sizes that the user can specify
To restrict or disable the Scripts combo box
You can provide a custom template for the Font dialog box, for example, if you want to include additional controls that are unique to your application. The ChooseFont function uses your custom template in place of the default template.
To provide a custom template for the Font dialog box
-Or-
You can provide a
To enable a hook procedure for the Font dialog box
After processing its
The hook procedure can send the WM_CHOOSEFONT_GETLOGFONT,
This topic describes sample code that displays a Font dialog box so a
user can choose the attributes of a font. The sample code first initializes a
This example sets the CF_SCREENFONTS flag to specify that the dialog box should display only screen fonts. It sets the CF_EFFECTS flag to display controls that allow the user to select strikeout, underline, and color options.
If ChooseFont returns TRUE, indicating that the user clicked the OK button, the structure pointed to by the lpLogFont member of the CHOOSEFONT structure contains information that describes the font and font attributes selected by the user. The rgbColors member contains the selected text color. The sample code uses this information to set the font and text color for the device context associated with the owner window.
HWND hwnd; // owner window
HDC hdc; // display device context of owner window
CHOOSEFONT cf; // common dialog box structure
static LOGFONT lf; // logical font structure
static DWORD rgbCurrent; // current text color
HFONT hfont, hfontPrev;
DWORD rgbPrev;
// Initialize CHOOSEFONT
ZeroMemory(&cf, sizeof(cf));
cf.lStructSize = sizeof (cf);
cf.hwndOwner = hwnd;
cf.lpLogFont = &lf;
cf.rgbColors = rgbCurrent;
cf.Flags = CF_SCREENFONTS | CF_EFFECTS;
if (ChooseFont(&cf)==TRUE) {
hfont = CreateFontIndirect(cf.lpLogFont);
hfontPrev = SelectObject(hdc, hfont);
rgbCurrent= cf.rgbColors;
rgbPrev = SetTextColor(hdc, rgbCurrent);
.
.
.
}