"正确" Windows上的对话框/ UI字体 [英] "Correct" Dialog / UI font on Windows

查看:152
本文介绍了"正确" Windows上的对话框/ UI字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用CreateWindow动态创建控件(例如编辑控件)时,通常以丑陋(粗体无衬线)字体开始。



通常,我通过抓住父对话框的字体并将其设置为控件来解决这个问题 - 我甚至不能说这是个好主意。 >

我如何 合法 获取正确的字体?


解决方案

在正确的方式来获取对话框中使用的字体,如消息框等将通过 SystemParametersInfo()函数:

  // C ++示例
NONCLIENTMETRICS指标;
metrics.cbSize = sizeof(NONCLIENTMETRICS);
:: SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS),
& metrics,0);
HFONT font = :: CreateFontIndirect(& metrics.lfMessageFont);
:: SendMessage(ctrlHWND,WM_SETFONT,(WPARAM)font,MAKELPARAM(TRUE,0));

不要忘记在控件销毁时销毁字体:

  :: DeleteObject(font); 

您可以查阅 NONCLIENTMETRICS SystemParametersInfo() 以查看还有什么其他系统参数可以检索。

When creating a control (e.g. an edit control) on the fly using CreateWindow, it usually starts out with an ugly (boldish sans serif) font.

Usually I wok around that by grabbing the parent dialog's font, and setting it to the control - I can't even say if this is a good idea.

How do I "legally" fetch the right font?

解决方案

The "correct" way to get the font used in dialog boxes like message boxes, etc. would be via the SystemParametersInfo() function:

// C++ example
NONCLIENTMETRICS metrics;
metrics.cbSize = sizeof(NONCLIENTMETRICS);
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
    &metrics, 0);
HFONT font = ::CreateFontIndirect(&metrics.lfMessageFont);
::SendMessage(ctrlHWND, WM_SETFONT, (WPARAM)font, MAKELPARAM(TRUE, 0));

Don't forget to destroy the font when the controls are destroyed:

::DeleteObject(font);

You can look up the MSDN documentation for NONCLIENTMETRICS and SystemParametersInfo() to see what other system-wide parameters you can retrieve.

这篇关于"正确" Windows上的对话框/ UI字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆