Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XP Theme Tab Background Color

156 views
Skip to first unread message

Erik Berry

unread,
Aug 1, 2007, 7:31:05 PM8/1/07
to
Is there any way to get the current XP theme's tab background color. By
default this color is white under XP, rather than the old default of
clBtnFace. I've got a custom component where I need to match the color at
runtime, but for various reasons, I can't use DrawParentBackground or
DrawThemeParentBackground, like the VCL does. I need the value as a TColor
to set a BackgroundColor property of a component that can't paint
transparent. Or is it not possible to get a single color, since it might be
a gradient, etc?

Erik

Yorai Aminov (TeamB)

unread,
Aug 1, 2007, 8:34:36 PM8/1/07
to
On 02/08/2007 02:31:05, Erik Berry wrote:

> Is there any way to get the current XP theme's tab background
> color.

That's a tricky one. The tab background is a gradient or a bitmap,
but asking XP for the gradient or background colors doesn't seem to
work. You can, however, get the background color hint, which is the
color custom controls should use if they can't use the theme drawing
routines. This works for me with using both the default (blue) and
"silver" themes:

uses
Themes, UxTheme;

function GetTabBackgroundColor: TColor;
var
TabTheme: HTHEME;
TabColor: Cardinal;
begin
Result := clBtnFace;
if ThemeServices.ThemesEnabled then
begin
TabTheme := ThemeServices.Theme[teTab];
try
if GetThemeColor(TabTheme, TABP_BODY, 0, TMT_FILLCOLORHINT,
TabColor) = S_OK then
Result := TabColor;
finally
CloseThemeData(TabTheme);
end;
end;
end;

--
Yorai Aminov (TeamB)
(TeamB cannot answer questions received via email.)
Shorter Path - http://www.shorterpath.com
Yorai's Page - http://www.yoraispage.com

Erik Berry

unread,
Aug 2, 2007, 2:57:08 PM8/2/07
to
Yorai Aminov (TeamB) wrote:
> That's a tricky one. The tab background is a gradient or a bitmap,
> but asking XP for the gradient or background colors doesn't seem to
> work. You can, however, get the background color hint, which is the
> color custom controls should use if they can't use the theme drawing
> routines. This works for me with using both the default (blue) and

Thanks, Yorai for your hints. I tested this under Vista with the default
theme/colors. In that case, the function returns $00F4F4F4 (light gray, but
not an exact math to clBtnFace) instead of the white background color that
tabs have by default. Maybe this is the best we can do, but I was hoping to
find a better match at least for the default colors where there is little/no
gradient present.

Erik

Yorai Aminov (TeamB)

unread,
Aug 2, 2007, 9:11:04 PM8/2/07
to
On 02/08/2007 21:57:08, Erik Berry wrote:

> Thanks, Yorai for your hints. I tested this under Vista with the
> default theme/colors. In that case, the function returns $00F4F4F4
> (light gray, but not an exact math to clBtnFace) instead of the
> white background color that tabs have by default.

Interesting. On XP, I get $00FDFBFB, which is very close to the tab
color. Vista might return better results with other constants.

> Maybe this is
> the best we can do, but I was hoping to find a better match at
> least for the default colors where there is little/no gradient
> present.

Try replacing TMT_FILLCOLORHINT with some of the other contstants
listed in the help for GetThemeColor - they might work under Vista.

The only other option I can think of is drawing a tab background to a
bitmap and retrieving one of the pixels. On XP, this gives me
$00FEFCFC for the top-left pixel:

function GetTabBackgroundColorFromBitmap: TColor;
var
B: TBitmap;


begin
Result := clBtnFace;
if ThemeServices.ThemesEnabled then
begin

B := TBitmap.Create;
try
B.Width := 128;
B.Height := 128;
ThemeServices.DrawElement(B.Canvas.Handle,
ThemeServices.GetElementDetails(ttBody),
Rect(0, 0, B.Width - 1, B.Height - 1), nil);
Result := B.Canvas.Pixels[0, 0];
finally
B.Free;

Erik Berry

unread,
Aug 2, 2007, 10:54:20 PM8/2/07
to
Yorai Aminov (TeamB) wrote:
> The only other option I can think of is drawing a tab background to a
> bitmap and retrieving one of the pixels. On XP, this gives me
> $00FEFCFC for the top-left pixel:

I should have thought of this -- it works great. I did change it to get the
64,64 pixel in case that is a better match for a gradient background, and I
made it cache the value for future calls, but your approach works perfectly.
It now returns clWhite as the default under Vista.

Thanks,
Erik

innen...@gmail.com

unread,
May 22, 2017, 4:16:26 AM5/22/17
to
Just for history: I've similar task and on Windows 7 I have found that GetThemeColor(TabTheme, TABP_AEROWIZARDBODY, 0, TMT_FILLCOLORHINT, TabColor) call give me Color value, similar to Tab's background.

innen...@gmail.com

unread,
May 22, 2017, 4:20:23 AM5/22/17
to
If I call CloseThemeData(TabTheme) in this code, my tab sheets loose background at all. This TabTheme gotten from system cache and does not need to be closed in Delphi.
0 new messages