Author: Jonas Bilinkevicius
How to change the color of a menu
Answer:
You can set the menu to owner-drawn and draw the items yourself in the OnDrawItem
handlers. This does not work for the menubar, however.
The menu colors are a system setting which the user can specify in the display
properties applet. You should not mess with that. One can do so when the app is
activated and restore the old setting when it is deactivated or closed, but that is
also not very satisfactory since the change still hits all other running apps as
well and in the case of changes to the color scheme it also may take a noticable
delay to take effect.
If you want to play with it: drop a TApplicationEvents component on the form,
connect the OnActivate and OnDeactivate events of it to handlers, add one for the
forms OnClose event, modify as below.
1 { ... }2 private3 { Private declarations }4 FOldMenuColor: TColorRef;
5 FOldMenuTextColor: TColorRef;
6 public7 { Public declarations }8 end;
9 10 var11 Form1: TForm1;
12 13 implementation14 15 {$R *.DFM}16 17 procedure TForm1.ApplicationEvents1Activate(Sender: TObject);
18 var19 newcolors: array[0..1] of TColorRef;
20 indices: array[0..1] of Integer;
21 begin22 FOldMenuColor := ColorToRGB(clMenu);
23 FOldMenuTextColor := ColorToRGB(clMenuText);
24 newcolors[0] := ColorToRGB(clAqua);
25 newcolors[1] := ColorToRGB(clNavy);
26 indices[0] := COLOR_MENU;
27 indices[1] := COLOR_MENUTEXT;
28 SetSysColors(2, indices, newcolors);
29 end;
30 31 procedure TForm1.ApplicationEvents1Deactivate(Sender: TObject);
32 var33 newcolors: array[0..1] of TColorRef;
34 indices: array[0..1] of Integer;
35 begin36 newcolors[0] := FOldMenuColor;
37 newcolors[1] := FOldMenuTextColor;
38 indices[0] := COLOR_MENU;
39 indices[1] := COLOR_MENUTEXT;
40 SetSysColors(2, indices, newcolors);
41 end;
42 43 procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
44 begin45 ApplicationEvents1Deactivate(self);
46 end;