Erik
> 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
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
> 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;
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