piscean
asked on
How to change Windows Color Scheme
My project is something like the Desktop Theme Manager in Windows 98 (difference is that it's in the background). I want to maintain the desktop settings of >100 Company PCs running Win98. My program runs after every logon. The purpose of this is to discard any changes made by the users. They seem to bypass the security.
I have successfully changed the wallpaper to the company logo by updating the registry and calling SystemParametersInfo(SPI_S ETDESKWALL PAPER, 0, 0, SPIF_SENDWININICHANGE). I have also updated the color settings in HKEY_CURRENT_USER\Control Panel\...
My problem is that I cannot tell Windows to refresh so that the new color scheme will take effect. When I looked at the Display properties, the change was reflected. Broadcasting WM_SYSCOLORCHANGE doesn't work. SetSysColors can change the colors but the settings are lost after the logoff/shutdown. I've read about SetSystemPaletteUse in the SDK but I don't seem to understand the documentation.
I have successfully changed the wallpaper to the company logo by updating the registry and calling SystemParametersInfo(SPI_S
My problem is that I cannot tell Windows to refresh so that the new color scheme will take effect. When I looked at the Display properties, the change was reflected. Broadcasting WM_SYSCOLORCHANGE doesn't work. SetSysColors can change the colors but the settings are lost after the logoff/shutdown. I've read about SetSystemPaletteUse in the SDK but I don't seem to understand the documentation.
Just remember the color store as RGB value
use RGB(R,G,B) and GetRValue,GetGValue,GetBVa lue
they will help you to get the color value for each color
Mohammed
use RGB(R,G,B) and GetRValue,GetGValue,GetBVa
they will help you to get the color value for each color
Mohammed
You said:
(1) I have also updated the color settings in HKEY_CURRENT_USER\Control Panel\...
(2) SetSysColors can change the colors but the settings are lost after the logoff/shutdown.
Don't the two things in combination solve the problem? (2) sets the colors right now, (1) after the next logoff/shutdown.
Regards, Madshi.
(1) I have also updated the color settings in HKEY_CURRENT_USER\Control Panel\...
(2) SetSysColors can change the colors but the settings are lost after the logoff/shutdown.
Don't the two things in combination solve the problem? (2) sets the colors right now, (1) after the next logoff/shutdown.
Regards, Madshi.
Hello
here's a simple sample it will change the background of desktop by using SetSysColors, and also will write to registry and save the values, and when you log off and back you will see the setting you choosed
//====
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ColorDialog1: TColorDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses Registry;
procedure TForm1.Button1Click(Sender : TObject);
var
I,J : Integer;
Reg : TRegistry;
R,G,B : string;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
I := COLOR_DESKTOP;
if ColorDialog1.Execute then
J := ColorDialog1.Color;
R := IntTostr(GetRvalue(J));
G := IntTostr(GetGvalue(J));
B := IntTostr(GetBvalue(J));
SetSysColors(1,I,J);
if Reg.OpenKey('Control Panel\Colors',False) then
Reg.WriteString('Backgroun d',R + ' '+ G + ' ' + B);
SetSysColors(1,I,J);
Reg.Free;
end;
end.
Mohammed
here's a simple sample it will change the background of desktop by using SetSysColors, and also will write to registry and save the values, and when you log off and back you will see the setting you choosed
//====
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ColorDialog1: TColorDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses Registry;
procedure TForm1.Button1Click(Sender
var
I,J : Integer;
Reg : TRegistry;
R,G,B : string;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
I := COLOR_DESKTOP;
if ColorDialog1.Execute then
J := ColorDialog1.Color;
R := IntTostr(GetRvalue(J));
G := IntTostr(GetGvalue(J));
B := IntTostr(GetBvalue(J));
SetSysColors(1,I,J);
if Reg.OpenKey('Control Panel\Colors',False) then
Reg.WriteString('Backgroun
SetSysColors(1,I,J);
Reg.Free;
end;
end.
Mohammed
I think you would be better off just exporting the appropropriate HKCU and placing the hive key file in a hidden folder. Then at HKLM\Software\Microsoft\Wi ndows\Curr entVersion \Run
Put in a command:
c:\windows\regedit32.exe /s 'c:\filename.reg'
where filename is the name you called the exported hive file. This will silent install the settings on the machine. When the user logs on the hive file is updated. You can put your wall paper settings and anything else in the machine you want as well.
If you still have problems write a small batch file that AutoExec.bat would call. This batch file would have a command in it to run c:\windows\regedit32.exe /s 'c:\filename.reg'
I do this at work all the time and it works great for me, but I do it for different reasons.
Put in a command:
c:\windows\regedit32.exe /s 'c:\filename.reg'
where filename is the name you called the exported hive file. This will silent install the settings on the machine. When the user logs on the hive file is updated. You can put your wall paper settings and anything else in the machine you want as well.
If you still have problems write a small batch file that AutoExec.bat would call. This batch file would have a command in it to run c:\windows\regedit32.exe /s 'c:\filename.reg'
I do this at work all the time and it works great for me, but I do it for different reasons.
ASKER
Thanks for your help guys. But I can do change the color scheme (In a somewhat long process... change the registry and call SetSysColors to fool the user of the refresh). What I really wanted to know is that if there's a message I have to broadcast after I've changed the color settings in HKEY_CURRENT_USER\Control Panel\Colors. As you can see in the case of the wallpaper, after I've changed HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper (and other values there ...), I have to broadcast a WM_SETTINGCHANGE to all windows to make the change in effect (or to trigger a refresh).
Is there a message that corresponds to refreshing after the color changes made?
Is there a message that corresponds to refreshing after the color changes made?
ASKER
gemarti,
I've tried that before and it does change the registry setting. But I need an immediate refresh after the change which importing to registry cannot do.
Thanks anyway ...
I've tried that before and it does change the registry setting. But I need an immediate refresh after the change which importing to registry cannot do.
Thanks anyway ...
No, I'm sorry. At least no documented message. There are a lot of registry values that get loaded only when Windows or the explorer starts up, and never again until the next reboot. And only a few things react on WM_SETTINGCHANGE.
Regards, Madshi.
Regards, Madshi.
>>SetSysColors to fool the user of the refresh
to do a refresh jstsnd f5 to the desktop.
that wont refresh the registry or your colors though..youll need at least a logoff for that key im sure.
to do a refresh jstsnd f5 to the desktop.
that wont refresh the registry or your colors though..youll need at least a logoff for that key im sure.
ASKER
What do you guys think are the procedures executed when you changed the settings and clicked OK or Apply in the Display properties? Changes are reflected immediately (both registry and display) without a restart/logoff isn't it? ...
inthe,
I can't (and should not) force a logoff. The user must be doing something (poor user ...) ... BTW, I also am sure there's a way to do this without a logoff ...
Thanks for the comments ... (can we try harder ...)
inthe,
I can't (and should not) force a logoff. The user must be doing something (poor user ...) ... BTW, I also am sure there's a way to do this without a logoff ...
Thanks for the comments ... (can we try harder ...)
ASKER
I mean "The user might be doing something ..."
ASKER
I mean "The user might be doing something ..."
>> What do you guys think are the procedures executed when you changed the settings and clicked OK or Apply in the Display properties?
Well, there's not much to think about. Windows calls an internal function (like SystemParametersInfoExExEx ), no doubt about that. It's just not documented and possibly different in every OS... :-(
Regards, Madshi.
Well, there's not much to think about. Windows calls an internal function (like SystemParametersInfoExExEx
Regards, Madshi.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
To be PAQ/Refund
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Thank you,
Russell
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
To be PAQ/Refund
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Thank you,
Russell
EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SetSysColors will not store the new value in the registry edit, so you need to store the value you choosed to the registry edit, windows store that in this key
[HKEY_CURRENT_USER\Control
"Background"="58 110 165"
if you change the color scheme to black the value will stroe in the registry as
[HKEY_CURRENT_USER\Control
"Background"="0 0 0"
Best regards
Mohammed Nasman