How to change the font style of the dialog#39;s title bar in MFC(如何在 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 中更改对话框标题栏的字体样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 MFC 中更改对话框标题栏的字体样式


基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01