可以使用逻辑调色板代替系统调色板吗?

发布于 2024-10-27 03:50:12 字数 167 浏览 2 评论 0原文

在我们的一个应用程序中,我们希望使用自定义颜色,并且在许多情况下基本上忽略标准 Windows 调色板(例如,将 WindowText 设置为蓝色而不是黑色)。我的想法是创建一个逻辑调色板并使用 SelectPalette 和 RealizePalette 将其应用到应用程序,但我找不到任何使用这些的好例子。这可以吗?

In one of our applications, we want to use custom colors and essentially ignore the standard windows palette in a number of cases (set WindowText to Blue rather than Black for example). My thought to do this is to just create a logical palette and apply that to the application using SelectPalette and RealizePalette, but I can't find any good examples of using these. Is this possible to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

画离情绘悲伤 2024-11-03 03:50:12

您要求的是 GetStockObject 的反函数(好吧,严格来说,还有一些函数需要像 GetSysColor 这样的索引,这也将是相关的) 。但是,没有这样的函数可以设置每个进程的颜色(除非您想使用系统范围的 SetSysColors,您的问题似乎排除了这一点)。您最好的选择 - 也是最简单的 - 是将这些函数挂接到您的进程中(Windows 为您执行写时复制部分,因此可以将其挂接到 gdi32.dll 占用的内存中)并返回您自己的对象(画笔、字体、钢笔、颜色)。尝试确保在应用程序完成后清理 GDI 对象。这正是您所要求的,但不一定是在 Delphi 中实现该效果的最简单方法。 编辑: David Heffernan 指出有关挂钩的建议没有考虑主题。他是对的。所以也许这不是最好的方法。

然而,考虑到您使用的是 Delphi,派生您想要自定义的 VCL 类可能是最简单的(对于控件和表单都很实用)。或者,您可以使用 RTTI 迭代表单的元素并根据需要修改元素(统一并按控件类型)。

如果您的应用程序仅需要应用程序中的某些控件,WM_CTLCOLOREDIT 和朋友可能是更简单的方法。

无论哪种方式:请考虑,如果应用程序使用熟悉的控制元素、样式、颜色......,那么应用程序的可用性和 UX(用户体验)通常会更好。

What you're asking for would be the inverse of GetStockObject (okay, strictly speaking there are a few more functions that take an index like GetSysColor that will be relevant, too). There is, however, no such function that sets those per process (unless you want to go for system-wide, SetSysColors, which your question seems to preclude). Your best bet - and easiest, too - would be to hook those functions within your process (Windows does the copy-on-write part for you, so hooking it inside the memory occupied by gdi32.dll is possible) and return your own objects (brushes, fonts, pens, colors). Try to make sure to clean up GDI objects once your application finishes. This would be exactly the stuff you're asking for, but not necessarily the easiest way to achieve the effect in Delphi. Edit: David Heffernan pointed out that the suggestion about hooking does not consider themes. He's right. So perhaps this is not the best way.

However, given you're using Delphi, it may be easiest to derive the VCL classes you want to customize (practical for both controls and forms). Alternatively you can use the RTTI to iterate over the elements of your form and modify the elements as needed (uniformly and by the control type).

If your application requires it only for some controls in the application, WM_CTLCOLOREDIT and friends my be the easier method.

Either way: please consider that the usability and UX (user experience) of applications is usually better if the application uses familiar control elements, styles, colors ...

韶华倾负 2024-11-03 03:50:12

为什么现在需要使用调色板?随意使用 RGB 值即可。

调色板可以追溯到 8 位(及更低)颜色设备的时代。现在我们都已经转向 16 位颜色,最近又转向 32 位颜色,它们已经成为了历史。

Why do you need to use palettes these days? Just use RGB values as you please.

Palettes date back to the days of 8 bit (and lower) colour devices. Now that we have all moved to 16 bit colour and more recently 32 bit colour they have become a relic.

揽清风入怀 2024-11-03 03:50:12

Tom,对于 VCL 中的某些控件,您所要求的操作比其他控件更容易完成。要获得更彻底的解决方案,您可能对 Delphi 的主题或换肤解决方案感兴趣。这不仅可以帮助您实现自定义颜色,还可以帮助您实现完全自定义的外观。

Delphi 有多种主题和换肤系统。您所讨论的方法(您所说的“逻辑调色板”实际上是 Windows 系统配色方案)归结为挂钩 Windows GetSysColor 函数,并且效果并不如您所希望的那样好。

相反,请尝试彻底的解决方案:皮肤(显示的链接适用于 SpTbxLib 皮肤)
在此处输入图像描述

顺便说一句,有些人讨厌皮肤应用程序(请参阅其他问题的评论),因此您实现的任何皮肤功能都应该有一个关闭开关。另外,有些人视力有限,依赖 Windows 高对比度主题工作。想想那些必须使用你建造的东西的穷人。

Tom, what you're asking for can be done more easily for some controls in the VCL, than for others. For a more thorough solution, you may be interested in a theming or skinning solution for Delphi. This will help you achieve not just custom colors, but a completely customized look.

There are a variety of theming and skinning systems for Delphi. The approach that you are talking about (what you called "logical palettes" is really the Windows system color scheme) boils down to hooking the Windows GetSysColor function, and doesn't work nearly as well as you would hope.

Instead, try the thorough solution: Skins (the link shown is for SpTbxLib skins)
enter image description here

Incidentally, some people hate skinned apps (see comments on other questions) and so any skin feature you implement should have an OFF switch. Also some people have limited vision and rely on windows high contrast theme working. Think of the poor people who have to use what you build.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文