如何在 MFC 中更改对话框标题栏的字体样式 [英] How to change the font style of the dialog's title bar in MFC

查看:78
本文介绍了如何在 MFC 中更改对话框标题栏的字体样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,在 MFC 中,对话框标题栏的字体与系统设置相对应.如何更改字体样式?

By default in MFC, the font of the dialog's title bar is in correspondence with the system settings. How can I change the font style?

推荐答案

这不仅仅是 MFC 的默认设置;它适用于所有 Windows 应用程序.这是因为操作系统会为所有窗口绘制标题栏,操作系统自然会尊重用户配置的设置.

This is not just an MFC default; it works that way for all Windows applications. That's because the operating system draws the title bar for all windows, and naturally the operating system respects the settings that the user has configured.

如果你想改变它并覆盖用户的设置(我真的怀疑你为什么要做这样的事情),那么你将需要绘制窗口的 整个-客户区(包括标题栏)掌握在自己手中.这是通过处理 WM_NCPAINT 来实现的消息(或者我想在 MFC 中,处理一个名为 OnWmNcPaint 之类的窗口的成员函数).

If you want to change that and override the user's settings (and I really question why you would want to do such a thing), then you will need to take the drawing of the window's entire non-client area (which includes the title bar) into your own hands. This is achieved by handling the WM_NCPAINT message (or I suppose in MFC, handling a member function of your window named something like OnWmNcPaint).

但请注意:这是一项相当高级的任务,而且很难做好.此外,它将打破 Aero 主题的玻璃造型和其他半透明效果.我不知道它在 Windows 8 上的作用,因为我还没有尝试过,但我想它也会破坏那里的东西.

But be forewarned: this is a fairly advanced task, and difficult to get right. Additionally, it will break the glass styling and other translucent effects of the Aero theme. I have no idea what it does on Windows 8 since I haven't tried it yet, but I imagine it breaks things there, too.

要使其与 Aero 主题正常工作,您需要在运行时检测 Aero 是否已启用,如果已启用,跳过一些额外的箍.如果 Aero 主题未启用,那么您将回退到处理 WM_NCPAINT 消息的旧方法.

To make it work properly with the Aero theme, you will need to detect at runtime whether Aero is enabled, and if it is, jump through some additional hoops. If the Aero theme is not enabled, then you fall back to the old method of handling the WM_NCPAINT message.

我有没有提到我不推荐这个?这是一个全局系统设置,而不是打算被应用程序覆盖的东西是有原因的.如果用户想在他们的标题栏中使用丑陋的字体,那是他们的特权.

Did I mention that I don't recommend this? There's a reason that this is a global system setting, not something intended to be overridden by applications. If the user wants to use an ugly font in their title bars, then that is their prerogative.

这篇关于如何在 MFC 中更改对话框标题栏的字体样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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