以编程方式设置标题栏和边框颜色 [英] Setting title bar and border colors programmatically

查看:126
本文介绍了以编程方式设置标题栏和边框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式更改应用程序的标题栏和边框颜色。我尝试了很多事情,但没有成功,因此决定在系统范围内更改这些颜色。因为我也可以在应用程序运行时更改标题栏和边框颜色,然后将其还原到应用程序末尾。 (受管理的环境,正在运行少量应用程序)

I am trying to change my application' s title bar and border colors programmatically. I tried lots of things but with no success, and decided to change these colors system-wide. Because it is also acceptable for me to change title bar and border colors as my application is running, and revert them back in the end of my application. (Managed environment, with small set of applications running)

是否可以动态更改这些颜色(整个过程或整个系统,除非可以进行整个过程的更改) )?您可以建议实现此目的的任何方法吗?

Is it possible to change these colors dynamically(process-wide, or system-wide unless process-wide change is possible)? Can you suggest any way to achieve this?

我尝试了以下操作,但它并没有满足我的要求:

I tried something like the following but it doesn' t do what I want:

int aElements[2] = {COLOR_WINDOW, COLOR_ACTIVECAPTION};
DWORD aOldColors[2];
DWORD aNewColors[2];

aOldColors[0] = GetSysColor(aElements[0]); 
aOldColors[1] = GetSysColor(aElements[1]); 
aNewColors[0] = RGB(0x80, 0x80, 0x80);  // light gray 
aNewColors[1] = RGB(0x80, 0x00, 0x80);  // dark purple 

SetSysColors(2, aElements, aNewColors);
SetSysColors(2, aElements, aOldColors);

预先感谢

编辑

这正是我想要的:

推荐答案

我不建议自定义边框和标题重绘。
很难正确地做到这一点。 Office仅在客户区域中使用正常边框自动绘制所有内容。
正确使用NC_PAINT会很痛苦,并且可能会引起闪烁。
特别困难的是最小化,最大化和关闭按钮的定位,因为每个窗口的操作方式都不相同。
还应考虑可访问性,使用的较大字体和自定义的用户设置。

I don't recommend to customize border and title redrawing. It's really hard to do it the right way. Office just draws everything by itself in the client area but using normal border. Using NC_PAINT the right way is a pain and may introduce flickering. Especially positioning the minimize,maximize and close buttons is difficult, because every windows does it differently. Also take into account accessibility, larger fonts used, customized user settings.

更改颜色的目的是什么?

Whats the purpose of changing the colors?

要更改全局颜色,您必须至少分离代码

To change the global colors you have to at least separate your code

//在应用程序启动时调用一次(例如在WM_CREATE中)

// call this once at startup of your application (e.g. in WM_CREATE)

SetSysColors(2, aElements, aNewColors); 

//在关闭应用程序时调用此命令(例如,在WM_DESTROY中)

// call this when closing you application (e.g. in WM_DESTROY)

SetSysColors(2, aElements, aOldColors); 

这篇关于以编程方式设置标题栏和边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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