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

查看:985
本文介绍了如何在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的默认设置,还包括MFC的默认设置.它适用于 all 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.

如果您要更改它并覆盖用户设置(我真的很想问为什么要这样做),那么您将需要绘制窗口的 entire -客户区(包括标题栏)掌握在您自己的手中.这是通过处理 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,如果已启用,请

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