我使用Win32 API和C/C++.我有一个HFONT,想用它来创建一个新的HFONT.新字体应使用完全相同的字体指标,但它应该是粗体.就像是:
HFONT CreateBoldFont(HFONT hFont) {
LOGFONT lf;
GetLogicalFont(hFont, &lf);
lf.lfWeight = FW_BOLD;
return CreateFontIndirect(&lf);
}
Run Code Online (Sandbox Code Playgroud)
"GetLogicalFont"是缺少的API(据我所知,无论如何).还有其他方法吗?最好是适用于Windows Mobile 5+的东西.
aru*_*rul 26
您想使用GetObject函数.
GetObject ( hFont, sizeof(LOGFONT), &lf );
Run Code Online (Sandbox Code Playgroud)
这样的事情 - 请注意,错误检查留给读者练习.:-)
static HFONT CreateBoldWindowFont(HWND window)
{
const HFONT font = (HFONT)::SendMessage(window, WM_GETFONT, 0, 0);
LOGFONT fontAttributes = { 0 };
::GetObject(font, sizeof(fontAttributes), &fontAttributes);
fontAttributes.lfWeight = FW_BOLD;
return ::CreateFontIndirect(&fontAttributes);
}
static void PlayWithBoldFont()
{
const HFONT boldFont = CreateBoldWindowFont(someWindow);
.
. // Play with it!
.
::DeleteObject(boldFont);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8066 次 |
| 最近记录: |