如何为 Win32 应用程序中的所有窗口设置默认字体? [英] How to set default font for all the windows in a Win32 Application?

查看:17
本文介绍了如何为 Win32 应用程序中的所有窗口设置默认字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的应用程序中的所有控件(编辑、列表控件等)都具有相同的字体,这不是系统默认的字体.我该怎么做呢?是否有任何设置应用程序默认字体的 Win32 API?

I want all the controls (edit,list control, etc) in my application to be having the same font which is not the system default. How do i do this? Is there any Win32 API that sets the application default font?

推荐答案

Windows 不为应用程序范围的字体提供任何机制.每个窗口类可能有自己的行为来选择默认使用的字体.它可能会尝试选择 Windows shell 对话框使用的字体,或者它可能只是使用自动选择到新 DC 中的可怕的位图系统"字体来绘制其文本.

Windows does not provide any mechanism for an application-wide font. Each window class may have its own behavior for choosing a font to use by default. It may try to select the font used by Windows shell dialogs, or it may simply draw its text using the horrid bitmap 'system' font automatically selected into new DCs.

Windows 常用控件窗口类均响应WM_SETFONT,这是标准的窗口消息,用于告诉窗口您希望它使用什么字体.当你实现自己的窗口类(尤其是新的子控件窗口类)时,你还应该为 WM_SETFONT 编写一个处理程序:

The Windows common control window classes all respond to WM_SETFONT, which is the standard window message for telling a window what font you want it to use. When you implement your own window classes (especially new child control window classes), you should also write a handler for WM_SETFONT:

  1. 如果您的窗口类有任何子窗口,您的 WM_SETFONT 处理程序应将消息转发给每个子窗口.
  2. 如果您的窗口类执行任何自定义绘图,请确保将您收到的 HFONT 保存在 WM_SETFONT 处理程序中,并将其选择到您在绘制窗口时使用的 DC.
  3. 如果您的窗口类被用作顶级窗口,则需要逻辑来选择自己的字体,因为它没有父窗口可以向其发送 WM_SETFONT 消息.
  1. If your window class has any child windows, your WM_SETFONT handler should forward the message to each of them.
  2. If your window class does any custom drawing, make sure to save the HFONT you receive in your WM_SETFONT handler and select it into the DC you use when drawing your window.
  3. If your window class is used as a top-level window, it will need logic to choose its own font, since it will have no parent window to send it a WM_SETFONT message.

请注意,对话管理器会为您完成其中的一些工作;实例化对话框模板时,新对话框的字体设置为模板中指定的字体,并且对话框发送 WM_SETFONT 其所有子控件.

Note that the dialog manager does some of this for you; when instantiating a dialog template, the new dialog's font is set to the font named in the template, and the dialog sends WM_SETFONT all of its child controls.

这篇关于如何为 Win32 应用程序中的所有窗口设置默认字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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