HOWTO: Change the Font Used by Dialog Controls in WindowsID: Q74737
|
In Windows 3.x, there are two ways to specify the font used by dialog
controls:
HWND hDlg;
HFONT hDlgFont;
LOGFONT lFont;
case WM_INITDIALOG:
/* Get dialog font and create non-bold version */
hDlgFont = NULL;
if ((hDlgFont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0L))
!= NULL)
{
if (GetObject(hDlgFont, sizeof(LOGFONT), (LPSTR)&lFont)
!= NULL)
{
lFont.lfWeight = FW_NORMAL;
if ((hDlgFont = CreateFontIndirect(&lFont)) != NULL)
{
SendDlgItemMessage(hDlg, CTR1, WM_SETFONT, hDlgFont, 0L);
// Send WM_SETFONT message to desired controls
}
}
}
else // user did not specify a font in the dialog template
{ // must simulate system font
lFont.lfHeight = 13;
lFont.lfWidth = 0;
lFont.lfEscapement = 0;
lFont.lfOrientation = 0;
lFont.lfWeight = 200; // non-bold font weight
lFont.lfItalic = 0;
lFont.lfUnderline = 0;
lFont.lfStrikeOut = 0;
lFont.lfCharSet = ANSI_CHARSET;
lFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
lFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lFont.lfQuality = DEFAULT_QUALITY;
lFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
lFont.lfFaceName[0] = NULL;
hDlgFont = CreateFontIndirect(&lFont);
SendDlgItemMessage(hDlg, CTR1, WM_SETFONT, hDlgFont,
(DWORD)TRUE);
// Send WM_SETFONT message to desired controls
}
return TRUE;
break;
Keywords : kbDlg kbNTOS kbGrpUser kbWinOS
Version :
Platform :
Issue type : kbhowto
Last Reviewed: March 7, 1999