Author: Jonas Bilinkevicius
The ActionMainMenuBar highlight color is always blue, even if I have the green
theme selected (the highlights should be green). How do I fix this? If I turn of
menu shadows in Windows, my app still shows menu shadows, so how do I use the
Shadows property to detect and fix this? Under Windows XP when XP Manifest is
included, the file menu shadow does not draw properly. Actually it is the right
border which does not draw properly. It is missing, it is a 3 sided box. How do I
fix this?
Answer:
Here is a solution I found to address all three problems I reported. Everything
seems to be good now and finally I can use this component. First I created a new
color map component which detects the correct colors (based on the XPColorMap
component). See below for the source. This fixes the color problem and the 3-sided
menu box problem. Even if the user changes themes during the application, the menus
will update with the new colors!
To fix the shadow problem do this on your menu's popup event. It checks if the
shadows option is enabled in Windows.
procedure TForm1.PopupActionBarEx1Popup(Sender: TObject);
var
DisplayShadow: Boolean;
begin
if CheckWin32Version(5, 1) and SystemParametersInfo(SPI_GETDROPSHADOW, 0,
@DisplayShadow, 0) then
PopupActionBarEx1.Shadows := DisplayShadow;
end;
The new color map component:
1 unit XPColorMapEx;
2
3 interface
4
5 uses
6 Windows, SysUtils, Classes, ActnMan, Graphics, GraphUtil;
7
8 type
9 TXPColorMapEx = class(TCustomActionBarColorMap)
10 public
11 { Public declarations }
12 procedure UpdateColors; override;
13 published
14 { Published declarations }
15 property ShadowColor;
16 property Color;
17 property DisabledColor;
18 property DisabledFontColor;
19 property DisabledFontShadow;
20 property FontColor;
21 property HighlightColor;
22 property HotColor;
23 property HotFontColor;
24 property MenuColor;
25 property FrameTopLeftInner;
26 property FrameTopLeftOuter;
27 property FrameBottomRightInner;
28 property FrameBottomRightOuter;
29 property BtnFrameColor;
30 property BtnSelectedColor;
31 property SelectedColor;
32 property SelectedFontColor;
33 property UnusedColor;
34 property OnColorChange;
35 end;
36
37 procedure register;
38
39 implementation
40
41 { Merge the two colors using the alpha percentage }
42
43 function BlendColors(First, Second: TColor; Alpha: Integer): TColor;
44 var
45 fR, fG, fB, sR, sG, sB: Integer;
46 begin
47 fR := GetRValue(First);
48 fG := GetGValue(First);
49 fB := GetBValue(First);
50 sR := GetRValue(Second);
51 sG := GetGValue(Second);
52 sB := GetBValue(Second);
53 Result := RGB(Round(((Alpha * fR) + ((100 - Alpha) * sR)) / 100), Round(((Alpha *
54 fG) + ((100 - Alpha) * sG)) / 100), Round(((Alpha * fB) + ((100 - Alpha) * sB)) /
55 100));
56 end;
57
58 procedure TXPColorMapEx.UpdateColors;
59 begin
60 inherited;
61 Color := clBtnFace;
62 MenuColor := clWindow;
63 BtnFrameColor := GetSysColor(COLOR_HIGHLIGHT);
64 BtnSelectedColor := GetSysColor(COLOR_BTNFACE);
65 DisabledFontColor := clGrayText;
66 DisabledFontShadow := clBtnHighlight;
67 DisabledColor := clGray;
68 FontColor := clWindowText;
69 FrameTopLeftInner := clWhite;
70 FrameTopLeftOuter := $007A868A;
71 FrameBottomRightInner := clWhite;
72 FrameBottomRightOuter := $007A868A;
73 HighlightColor := GetHighLightColor(clBtnFace, 15);
74 HotColor := clDefault;
75 HotFontColor := clDefault;
76 SelectedColor := BlendColors(GetSysColor(COLOR_HIGHLIGHT), clWhite, 33);
77 SelectedFontColor := clBlack;
78 ShadowColor := cl3DDkShadow;
79 UnusedColor := GetHighLightColor(clBtnFace, 15);
80 end;
81
82 procedure register;
83 begin
84 RegisterComponents('Samples', [TXPColorMapEx]);
85 end;
86
87 end.
|