Solved

changing system color

Posted on 2000-03-22
8
321 Views
Last Modified: 2010-04-04
I've tried to change the colorsettings for the active window title with SetSysColors. The function return <>0 but nothing happens!!

(GetSysColor seems to work)

OS = win98 and delphi4

help,
0
Comment
Question by:staf_simons
  • 3
  • 3
  • 2
8 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 2644894
hi,
here is  ademo of using setsyscolor taht works fine on win98 with delphi4:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    StringGrid1: TStringGrid;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{we make a function so you can use your specified hex color}
Function HexToInt(Hex : string) : Integer;
begin
HexToInt := StrToInt('$' + Hex);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ColorIndex: array [1..5] of integer;
  ColorValue: array [1..5] of longint;
begin
   ColorIndex[1] := COLOR_3DHILIGHT;
   ColorValue[1]:=hextoint('E8FCFF');
   SetSysColors(1,ColorIndex,ColorValue);
   PostMessage(HWND_BROADCAST,WM_SYSCOLORCHANGE,0,0);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  ColorIndex: array [1..5] of integer;
  ColorValue: array [1..5] of longint;
begin
   ColorIndex[1] := COLOR_3DHILIGHT;
   ColorValue[1]:=HextoInt('FFFFFF');
   SetSysColors(1,ColorIndex,ColorValue);
   PostMessage(HWND_BROADCAST,WM_SYSCOLORCHANGE,0,0);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  ColorIndex: array [1..5] of integer;
  ColorValue: array [1..5] of longint;
begin
    ColorIndex[1] := COLOR_3DFACE;
    ColorValue[1]:=hextoint('E8FCFF');
    SetSysColors(1,ColorIndex,ColorValue);
    PostMessage(HWND_BROADCAST,WM_SYSCOLORCHANGE,0,0);
  // showmessage(inttohex(colorvalue[1],6));
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  ColorIndex: array [1..5] of integer;
  ColorValue: array [1..5] of longint;
begin
    ColorIndex[1] := COLOR_3DFACE;
    ColorValue[1]:=CLSilver;
    SetSysColors(1,ColorIndex,ColorValue);
    PostMessage(HWND_BROADCAST,WM_SYSCOLORCHANGE,0,0);
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  ColorIndex: array [1..5] of integer;
  ColorValue: array [1..5] of longint;
begin
    ColorIndex[1] := COLOR_HIGHLIGHT;
    ColorValue[1]:=clred;
    SetSysColors(1,ColorIndex,ColorValue);
    PostMessage(HWND_BROADCAST,WM_SYSCOLORCHANGE,0,0);
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  ColorIndex: array [1..5] of integer;
  ColorValue: array [1..5] of longint;
begin
   ColorIndex[1] := COLOR_HIGHLIGHT;
   ColorValue[1]:=clnavy;
   SetSysColors(1,ColorIndex,ColorValue);
   PostMessage(HWND_BROADCAST,WM_SYSCOLORCHANGE,0,0);
end;

end.



be careful using the color consts because some of them have names that mean different to what we would think.

Regards Barry
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2644905
In my computer it work only if I declare color as array of byte, instead array of longint.

procedure TForm1.SpeedButton1Click(Sender: TObject);
var AI : dword;
    AC : array[0..2] of byte;
begin
   AC[0]:=$00;
   AC[1]:=$ff;
   AC[2]:=$00;
   AI:=COLOR_ActiveCaption;
   SetSysColors(1,AI,AC);
end;


Cheers,
Igor.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2644919
Ok, I found my bug.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:staf_simons
ID: 2651466
hi inthe,

ok, you set me the way but...

it works fine with 1 color change but i have to do it with 6!!!

now i do it 1 at a time and it's ok but it must be possible to do them all at once dont't you think ?

regards
staf
0
 

Author Comment

by:staf_simons
ID: 2651478
hi Barry,

what's the reason u make an array [1..5]
and only use 1 entry?....

i think the solution is there somewhere

staf
0
 
LVL 17

Expert Comment

by:inthe
ID: 2651842

>>what's the reason u make an array
>>[1..5] and only use 1 entry?....

hehe ,i have no idea there must have been a reason..
(the code is from one of my first e.e questions so was a while ago since i tried it)

if you want to use more of the colors
just use more of the array  and call
SetSysColors(n,ColorIndex,ColorValue);

where n is amount of colors to change.

let me know how it goes i'll be back tommorow sometime to check was ok.

0
 

Author Comment

by:staf_simons
ID: 2652764
hihi,

first of all, it works but why ???

unit
..
..
..
var
   SysColorNames : array[0..6] of WORD
   SysColorValues : array[0..6] od DWORD

implementation

..
..
..
procedure TForm1.FormCreate(Sender : TObject);

..
..
   SysColorNames[0] := COLOR_ACTIVECAPTION;

   SysColorNames[1] := COLOR_INACTIVECAPTION;

   SysColorNames[2] := COLOR_GRADIENTACTIVECAPTION;

   SysColorNames[3] := COLOR_GRADIENTINACTIVECAPTION;

   SysColorNames[4] := COLOR_CAPTIONTEXT;
   SysColorNames[5] := COLOR_INACTIVECAPTIONTEXT;
..
..
..
procedure TForm1.ChangeSysColorCaption
..
..
..
color1 := ColorToRGB(clWhite);
color2 := ColorToRGB(clBlack);
SysColorValues[0] := color1;
SysColorValues[1] := color1;
SysColorValues[2] := color1;
SysColorValues[3] := color1;
SysColorValues[4] := color2;
SysColorValues[5] := color2;

SetSysColors(6,syscolorNames,syscolorValues);

---------

see what is the result of that !!!
when you put

SysColorValues[2] := SysColorValues[4];

just before SetSysColors and you change that line to

SetSysColors(3,syscolorNames,syscolorValues);

then it works !!!

so problem solved but ....

regards staf

0
 
LVL 17

Expert Comment

by:inthe
ID: 2655548
hey this setsyscolors is a bit mental ;-)
this must be why i was doing one at a time in original example.

it certainly dont seem to work as the documentation(in win32.hlp) discusses..
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
proper way to parse text with delphi 7 119
add combobox item based on numbers 9 141
Intraweb download file link ? 1 132
can't find the executable in Simulator 1 89
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now