开发者

Can logical palettes be used in place of the system palette?

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 Blac开发者_开发知识库k 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?


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 ...


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.


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)

Can logical palettes be used in place of the system palette?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜