Compartilhar via


ChooseFont function

Creates a Font dialog box that enables the user to choose attributes for a logical font. These attributes include a font family and associated font style, a point size, effects (underline, strikeout, and text color), and a script (or character set).

Syntax

BOOL WINAPI ChooseFont(
  _Inout_ LPCHOOSEFONT lpcf
);

Parameters

  • lpcf [in, out]
    Type: LPCHOOSEFONT

    A pointer to a CHOOSEFONT structure that contains information used to initialize the dialog box. When ChooseFont returns, this structure contains information about the user's font selection.

Return value

Type: BOOL

If the user clicks the OK button of the dialog box, the return value is TRUE. The members of the CHOOSEFONT structure indicate the user's selections.

If the user cancels or closes the Font dialog box or an error occurs, the return value is FALSE. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values.

CDERR_DIALOGFAILURE

CDERR_FINDRESFAILURE

CDERR_NOHINSTANCE

CDERR_INITIALIZATION

CDERR_NOHOOK

CDERR_LOCKRESFAILURE

CDERR_NOTEMPLATE

CDERR_LOADRESFAILURE

CDERR_STRUCTSIZE

CDERR_LOADSTRFAILURE

CFERR_MAXLESSTHANMIN

CDERR_MEMALLOCFAILURE

CFERR_NOFONTS

CDERR_MEMLOCKFAILURE

Remarks

You can provide a CFHookProc hook procedure for a Font dialog box. The hook procedure can process messages sent to the dialog box. To enable a hook procedure, set the CF_ENABLEHOOK flag in the Flags member of the CHOOSEFONT structure and specify the address of the hook procedure in the lpfnHook member.

The hook procedure can send the WM_CHOOSEFONT_GETLOGFONT, WM_CHOOSEFONT_SETFLAGS, and WM_CHOOSEFONT_SETLOGFONT messages to the dialog box to get and set the current values and flags of the dialog box.

Examples

For an example, see Choosing a Font.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Commdlg.h (include Windows.h)

Library

Comdlg32.lib

DLL

Comdlg32.dll

Unicode and ANSI names

ChooseFontW (Unicode) and ChooseFontA (ANSI)

See also

Reference

CFHookProc

CHOOSEFONT

CommDlgExtendedError

WM_CHOOSEFONT_GETLOGFONT

WM_CHOOSEFONT_SETFLAGS

WM_CHOOSEFONT_SETLOGFONT

Conceptual

Common Dialog Box Library

Other Resources

LOGFONT