更改应用程序标题栏的颜色
使用Delphi 7尝试从窗口主题更改软件标题栏的颜色。我见过允许您更改所有程序的所有标题栏的代码,但我只想更改我的程序。
有人见过/做过这样的事情吗?如果需要的话,不介意支付组件费用。
With Delphi 7 trying to change the color of the title bar of the software from the window theme. I have seen code which allows you to change ALL the title bars of all programs, but I am just wanting to change my program.
Anyone seen/done anything like this? Don't mind paying for a component if needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信 Windows 将 WM_NCPAINT 消息发送到应用程序何时应绘制窗口框架(包括标题栏)。默认行为是回退到绘制默认框架的默认 Windows 处理程序。您可以替换它,或者在之后重新绘制标题栏部分。
这看起来是一个很好的例子: http://delphi.about.com/od /adptips2006/qt/draw_captionbar.htm
I believe Windows sends the WM_NCPAINT message to an application when it should paint the window frame including the title bar. The default behaviour is to fall back to the default Windows handler which draws the default frame. You could replace this, or re-paint the title-bar section right after.
This looks like a good example: http://delphi.about.com/od/adptips2006/qt/draw_captionbar.htm
Stijn 的答案并不完全完整,因为当窗口被(取消)激活时,窗口的标题和边框也会被重新绘制。因此,除了
WM_NCPAINT
之外,您还需要处理WM_NCACTIVATE
。不幸的是,这不能简单地替换,因为默认消息处理程序中还有其他代码(除了绘图代码)需要执行。但是调用默认处理程序将导致首先绘制默认标题和边框,然后您需要用您想要的颜色绘制它们,从而导致闪烁。解决此问题的一种方法是调整调用默认消息处理程序所用的绘图区域。请参阅“绘图标题栏在带有主题的 XP 上”,这是一个使用 Windows API 调用的示例,可以轻松地转换为 Delphi。请注意,这仅处理标题栏中的文本,但原则适用。
The answer by Stijn is not fully complete, as the caption and border of the window will also be redrawn when it is (de-)activated. So in addition to
WM_NCPAINT
you will also need to handleWM_NCACTIVATE
. Unfortunately this can not simply be replaced, as there is other code in the default message handler (apart from drawing code) that needs to be executed. But calling the default handler will in turn lead to the default caption and border being drawn first, which you would then need to draw over with your intended colour, resulting in flicker.One way to work around this is to adjust the drawing region that the default message handler is called with. See "Drawing titlebar on XP with themes" for an example using Windows API calls that should easily translate to Delphi. Note that this deals only with the text in the caption bar, but the principle applies.
您可能会看一下蒙皮库。 DevExpress 的 ExpressSkin 是一个不错的选择。
You might take a look at a skinning library. ExpressSkin by DevExpress is a good one.