#include <commdlg.h> |
BOOL ChooseFont(lpcf) | |||||
CHOOSEFONT FAR*lpcf; | /* address of structure with initialization data | */ |
The ChooseFont function creates a system-defined dialog box from which the user can select a font, a font style (such as bold or italic), a point size, an effect (such as strikeout or underline), and a color.
lpcf
Points to a CHOOSEFONT structure that initially contains information necessary to initialize the dialog box. When the ChooseFont function returns, this structure contains information about the user's font selection. The CHOOSEFONT structure has the following form:
#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;
For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.
The return value is nonzero if the function is successful. Otherwise, it is zero.
Use the CommDlgExtendedError function to retrieve the error value, which may be one of the following:
CDERR_FINDRESFAILURE
CDERR_INITIALIZATION
CDERR_LOCKRESFAILURE
CDERR_LOADRESFAILURE
CDERR_LOADSTRFAILURE
CDERR_MEMALLOCFAILURE
CDERR_MEMLOCKFAILURE
CDERR_NOHINSTANCE
CDERR_NOHOOK
CDERR_NOTEMPLATE
CDERR_STRUCTSIZE
CFERR_MAXLESSTHANMIN
CFERR_NOFONTS
The following example initializes a CHOOSEFONT structure and then displays a font dialog box:
LOGFONT
lf; CHOOSEFONT cf; /* Set all structure fields to zero. */ memset(&cf, 0, sizeof(CHOOSEFONT)); cf.lStructSize = sizeof(CHOOSEFONT); cf.hwndOwner = hwnd; cf.lpLogFont = &lf; cf.Flags = CF_SCREENFONTS | CF_EFFECTS; cf.rgbColors = RGB(0, 255, 255); /* light blue */ cf.nFontType = SCREEN_FONTTYPE; ChooseFont(&cf);