Mirror

How to change the system colours (Views: 710)


Problem/Question/Abstract:

How to change the system colours

Answer:

Solve 1:

procedure TMainForm.Button4Click(Sender: TObject);
var
  nColorIndex: array[1..2] of integer;
  nColorValue: array[1..2] of longint;
begin
  nColorIndex[1] := COLOR_ACTIVECAPTION;
  nColorIndex[2] := COLOR_BTNFACE;
  nColorValue[1] := clBlue; {define the color you want}
  nColorValue[2] := clRed; {in that case is the caption bar and button color}
  SetSysColors(2, nColorIndex, nColorValue);
  PostMessage(HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0);
end;

You could have a look into the "Win32 API reference", under the "SetSysColors" section. There, if you directly go to "GetSysColors" you'll get alist of the places where you can change the colors. (e.g taskbar, borders, etc). In your case use COLOR_BACKGROUND and COLOR_DESKTOP.


Solve 2:

procedure TForm1.Button1Click(Sender: TObject);
const
  ColCount = 2;
  Elements: array[0..ColCount - 1] of Integer = (COLOR_WINDOW, COLOR_WINDOWTEXT);
  Colors: array[0..ColCount - 1] of TColorRef = (clBlue, clYellow);
begin
  if not SetSysColors(ColCount, Elements[0], Colors[0]) then
    RaiseLastWin32Error;
end;

<< Back to main page