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_SETDESKWALLPAPER, 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.
LVL 1
pisceanAsked:
Who is Participating?
 
PashaModConnect With a Mentor Commented:
Paq'ed and points not refunded

PashaMod
CS Moderator @Experts Exchange
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

  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 Panel\Colors]
"Background"="58 110 165"

if you change the color scheme to black the value will stroe in the registry as

[HKEY_CURRENT_USER\Control Panel\Colors]
"Background"="0 0 0"

Best regards
Mohammed Nasman

0
 
Mohammed NasmanSoftware DeveloperCommented:
Just remember the color store as RGB value
use RGB(R,G,B) and GetRValue,GetGValue,GetBValue
they will help you to get the color value for each color

Mohammed
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
MadshiCommented:
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.
0
 
Mohammed NasmanSoftware DeveloperCommented:
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('Background',R + ' '+ G + ' ' + B);
  SetSysColors(1,I,J);
  Reg.Free;
end;

end.

Mohammed
0
 
gemartiCommented:
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\Windows\CurrentVersion\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.

0
 
pisceanAuthor Commented:
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?
0
 
pisceanAuthor Commented:
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 ...
0
 
MadshiCommented:
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.
0
 
intheCommented:
>>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.

0
 
pisceanAuthor Commented:
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 ...)
0
 
pisceanAuthor Commented:
I mean "The user might be doing something ..."
0
 
pisceanAuthor Commented:
I mean "The user might be doing something ..."
0
 
MadshiCommented:
>> 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.
0
 
Russell LibbySoftware Engineer, Advisory Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.