CHOOSEFONT

3.1

#include <commdlg.h>

typedef struct tagCHOOSEFONT {  /* cf */
    DWORD           lStructSize;
    HWND            hwndOwner;
    HDC             hDC;
    LOGFONT FAR*    lpLogFont;
    int             iPointSize;
    DWORD           Flags;
    COLORREF        rgbColors;
    LPARAM          lCustData;
    UINT (CALLBACK* lpfnHook)(HWND, UINT, WPARAM, LPARAM);
    LPCSTR          lpTemplateName;
    HINSTANCE       hInstance;
    LPSTR           lpszStyle;
    UINT            nFontType;
    int             nSizeMin;
    int             nSizeMax;

} CHOOSEFONT;

The CHOOSEFONT structure contains information that the system uses to initialize the system-defined Font dialog box. After the user chooses the OK button to close the dialog box, the system returns information about the user's selection in this structure.

Members

lStructSize

Specifies the length of the structure, in bytes. This member is filled on input.

hwndOwner

Identifies the window that owns the dialog box. This member can be any valid window handle, or it should be NULL if the dialog box is to have no owner.

If the CF_SHOWHELP flag is set, hwndOwner must identify the window that owns the dialog box. The window procedure for this owner window receives a notification message when the user chooses the Help button. (The identifier for the notification message is the value returned by the RegisterWindowMessage function when HELPMSGSTRING is passed as its argument.)

This member is filled on input.

hDC

Identifies either the device context or the information context of the printer for which fonts are to be listed in the dialog box. This member is used only if the Flags member specifies the CF_PRINTERFONTS flag; otherwise, this member is ignored.

This member is filled on input.

lpLogFont

Points to a LOGFONT structure. If an application initializes the members of this structure before calling ChooseFont and sets the CF_INITTOLOGFONTSTRUCT flag, the ChooseFont function initializes the dialog box with the font that is the closest possible match. After the user chooses the OK button to close the dialog box, the ChooseFont function sets the members of the LOGFONT structure based on the user's final selection.

This member is filled on input and output.

iPointSize

Specifies the size of the selected font, in tenths of a point. The ChooseFont function sets this value after the user chooses the OK button to close the dialog box.

Flags

Specifies the dialog box initialization flags. This member can be a combination of the following values:

Value Meaning

CF_APPLY Specifies that the ChooseFont function should enable the Apply button.
CF_ANSIONLY Specifies that the ChooseFont function should limit font selection to those fonts that use the Windows character set. (If this flag is set, the user cannot select a font that contains only symbols.)
CF_BOTH Causes the dialog box to list the available printer and screen fonts. The hDC member identifies either the device context or the information context associated with the printer.
CF_TTONLY Specifies that the ChooseFont function should enumerate and allow the selection of only TrueType fonts.
CF_EFFECTS Specifies that the ChooseFont function should enable strikeout, underline, and color effects. If this flag is set, the lfStrikeOut and lfUnderline members of the LOGFONT structure and the rgbColors member of the CHOOSEFONT structure can be set before calling ChooseFont. And, if this flag is not set, the ChooseFont function can set these members after the user chooses the OK button to close the dialog box.
CF_ENABLEHOOK Enables the hook function specified in the lpfnHook member of this structure.
CF_ENABLETEMPLATE Indicates that the hInstance member identifies a data block that contains the dialog box template pointed to by lpTemplateName.
CF_ENABLETEMPLATEHANDLE Indicates that the hInstance member identifies a data block that contains a pre-loaded dialog box template. If this flag is specified, the system ignores the lpTemplateName member.
CF_FIXEDPITCHONLY Specifies that the ChooseFont function should select only monospace fonts.
CF_FORCEFONTEXIST Specifies that the ChooseFont function should indicate an error condition if the user attempts to select a font or font style that does not exist.
CF_INITTOLOGFONTSTRUCT Specifies that the ChooseFont function should use the LOGFONT structure pointed to by lpLogFont to initialize the dialog box controls.
CF_LIMITSIZE Specifies that the ChooseFont function should select only font sizes within the range specified by the nSizeMin and nSizeMax members.
CF_NOFACESEL Specifies that there is no selection in the Font (face name) combo box. Applications use this flag to support multiple font selections. This flag is set on input and output.
CF_NOOEMFONTS Specifies that the ChooseFont function should not allow vector-font selections. This flag has the same value as CF_NOVECTORFONTS.
CF_NOSIMULATIONS Specifies that the ChooseFont function should not allow graphics-device-interface (GDI) font simulations.
CF_NOSIZESEL Specifies that there is no selection in the Size combo box. Applications use this flag to support multiple size selections. This flag is set on input and output.
CF_NOSTYLESEL Specifies that there is no selection in the Font Style combo box. Applications use this flag to support multiple style selections. This flag is set on input and output.
CF_NOVECTORFONTS Specifies that the ChooseFont function should not allow vector-font selections. This flag has the same value as CF_NOOEMFONTS.
CF_PRINTERFONTS Causes the dialog box to list only the fonts supported by the printer associated with the device context or information context that is identified by the hDC member.
CF_SCALABLEONLY Specifies that the ChooseFont function should allow the selection of only scalable fonts. (Scalable fonts include vector fonts, some printer fonts, TrueType fonts, and fonts that are scaled by other algorithms or technologies.)
CF_SCREENFONTS Causes the dialog box to list only the screen fonts supported by the system.
CF_SHOWHELP Causes the dialog box to show the Help button. If this option is specified, the hwndOwner must not be NULL.
CF_USESTYLE Specifies that the lpszStyle member points to a buffer that contains a style-description string that the ChooseFont function should use to initialize the Font Style box. When the user chooses the OK button to close the dialog box, the ChooseFont function copies the style description for the user's selection to this buffer.
CF_WYSIWYG Specifies that the ChooseFont function should allow the selection of only fonts that are available on both the printer and the screen. If this flag is set, the CF_BOTH and CF_SCALABLEONLY flags should also be set.

These flags may be set when the structure is initialized, except where specified.

rgbColors

If the CF_EFFECTS flag is set, this member contains the red, green, and blue (RGB) values the ChooseFont function should use to set the text color. After the user chooses the OK button to close the dialog box, this member contains the RGB values of the color the user selected.

This member is filled on input and output.

lCustData

Specifies application-defined data that the application passes to the hook function. The system passes a pointer to the CHOOSEFONT data structure in the lParam parameter of the WM_INITDIALOG message; the lCustData member can be retrieved using this pointer.

lpfnHook

Points to a hook function that processes messages intended for the dialog box. To enable the hook function, an application must specify the CF_ENABLEHOOK value in the Flags member; otherwise, the system ignores this structure member. The hook function must return zero to pass a message that it didn't process back to the dialog box procedure in COMMDLG.DLL. The hook function must return a nonzero value to prevent the dialog box procedure in COMMDLG.DLL from processing a message it has already processed.

This member is filled on input.

lpTemplateName

Points to a null-terminated string that specifies the name of the resource file for the dialog box template to be substituted for the dialog box template in COMMDLG.DLL. An application can use the MAKEINTRESOURCE macro for numbered dialog box resources. This member is used only if the Flags member specifies the CF_ENABLETEMPLATE flag; otherwise, this member is ignored.

This member is filled on input.

hInstance

Identifies a data block that contains the dialog box template specified by the lpTemplateName member. This member is used only if the Flags member specifies the CF_ENABLETEMPLATE or the CF_ENABLETEMPLATEHANDLE flag; otherwise, this member is ignored.

This member is filled on input.

lpszStyle

Points to a buffer that contains a style-description string for the font. If the CF_USESTYLE flag is set, the ChooseFont function uses the data in this buffer to initialize the Font Style box. When the user chooses the OK button to close the dialog box, the ChooseFont function copies the string in the Font Style box into this buffer.

The buffer pointed to by lpszStyle must be at least LF_FACESIZE bytes long.

This member is filled on input and output.

nFontType

Specifies the type of the selected font. This member can be one or more of the values in the following list:

Value Meaning

BOLD_FONTTYPE Specifies that the font is bold. This value applies only to TrueType fonts. This value corresponds to the value of the ntmFlags member of the NEWTEXTMETRIC structure.
ITALIC_FONTTYPE Specifies that the font is italic. This value applies only to TrueType fonts. This value corresponds to the value of the ntmFlags member of the NEWTEXTMETRIC structure.
PRINTER_FONTTYPE Specifies that the font is a printer font.
REGULAR_FONTTYPE Specifies that the font is neither bold nor italic. This value applies only to TrueType fonts. This value corresponds to the value of the ntmFlags member of the NEWTEXTMETRIC structure.
SCREEN_FONTTYPE Specifies that the font is a screen font.
SIMULATED_FONTTYPE Specifies that the font is simulated by GDI. This is not set if the CF_NOSIMULATIONS flag is set.

nSizeMin

Specifies the minimum point size that a user can select. The ChooseFont function will recognize this member only if the CF_LIMITSIZE flag is set.

This member is filled on input.

nSizeMax

Specifies the maximum point size that a user can select. The ChooseFont function will recognize this member only if the CF_LIMITSIZE flag is set.

This member is filled on input.

See Also

ChooseFont