windows 消息WM_SETFONT 会做到这一点。首先应该创建一个字体,然后在WM_SETFONT 的参数中使用它。
创建字体和窗口后,使用
SendMessage(wnd, WM_SETFONT, (WPARAM)font, FALSE);
设置窗口的默认字体。
如果你想使用默认的 windows 字体,你可以像这样创建一个:
HFONT font = NULL;
NONCLIENTMETRICS ncm;
memset(&ncm, 0, sizeof(NONCLIENTMETRICS));
ncm.cbSize = sizeof(NONCLIENTMETRICS);
if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0)) {
font = CreateFontIndirect(&ncm.lfMessageFont);
}
NONCLIENTMETRICS 中还有其他默认字体可供您使用。
当然你也可以根据字体名称和其他信息创建字体,但不能保证不同系统上都有这样的字体。
HFONT CreateFont(
int nHeight, // height of font
int nWidth, // average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
DWORD fdwItalic, // italic attribute option
DWORD fdwUnderline, // underline attribute option
DWORD fdwStrikeOut, // strikeout attribute option
DWORD fdwCharSet, // character set identifier
DWORD fdwOutputPrecision, // output precision
DWORD fdwClipPrecision, // clipping precision
DWORD fdwQuality, // output quality
DWORD fdwPitchAndFamily, // pitch and family
LPCTSTR lpszFace // typeface name
);