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

查看:1623
本文介绍了如何设置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外壳对话框使用的字体,或者可能会简单地使用自动选择到新数据中心的可怕的位图系统字体来绘制文本。

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天全站免登陆