WM_SETFONT
wParam = (WPARAM) hfont; /* handle of the font */
lParam = (LPARAM) MAKELONG((WORD) fRedraw, 0); /* redraw flag */
An application sends the WM_SETFONT message to specify the font that a control is to use when drawing text.
hfont
Value of wParam. Specifies the handle of the font. If this parameter is NULL, the control will use the default system font to draw text.
fRedraw
Value of the low-order word of lParam. Specifies whether the control should be redrawn immediately upon setting the font. Setting the fRedraw parameter to TRUE causes the control to redraw itself.
An application should return zero if it processes this message.
The WM_SETFONT message applies to all controls, not just those in dialog boxes.
The best time for the owner of a dialog box to set the font of the control is when it receives the WM_INITDIALOG message. The application should call the DeleteObject function to delete the font when it is no longer needed—for example, after the control is destroyed.
The size of the control is not changed as a result of receiving this message. To prevent Windows from clipping text that does not fit within the boundaries of the control, the application should correct the size of the control window before changing the font.
Before Windows creates a dialog box with the DS_SETFONT style, Windows sends the WM_SETFONT message to the dialog box window before creating the controls. An application creates a dialog box with the DS_SETFONT style by calling any of the following functions:
The DialogBoxHeader structure that the application passes to these functions must have the DS_SETFONT style set and must contain the wPointSize and szFaceName members that define the font the dialog box will use to draw text.
For more information about the DialogBoxHeader structure, see Chapter 7,
“Resource Formats Within Executable Files,” in the Microsoft Windows
Programmer's Reference, Volume 4.
This example changes the font used by controls in a dialog box to a font that is not bold.
HFONT hDlgFont;
LOGFONT lFont;
case WM_INITDIALOG:
/* Get dialog box font and create version that is not bold. */
hDlgFont = (HFONT) NULL;
if ((hDlgFont = (HFONT) SendMessage(hdlg, WM_GETFONT, 0, 0L))) {
if (GetObject(hDlgFont, sizeof(LOGFONT), (LPSTR) &lFont)) {
lFont.lfWeight = FW_NORMAL;
if (hDlgFont = CreateFontIndirect((LPLOGFONT) &lFont)) {
SendDlgItemMessage(hdlg, ID_CTRL1, WM_SETFONT,
hDlgFont, 0L);
SendDlgItemMessage(hdlg, ID_CTRL2, WM_SETFONT,
hDlgFont, 0L);
.
. /* Set font for remaining controls. */
.
}
}
}
return TRUE;
CreateDialogIndirect, CreateDialogIndirectParam, DeleteObject, DialogBoxIndirect, DialogBoxIndirectParam