Solved

How to change Windows Color Scheme

Posted on 2001-07-20
15
913 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:piscean
  • 5
  • 3
  • 3
  • +4
15 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6304402
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
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6304439
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
 
LVL 20

Expert Comment

by:Madshi
ID: 6304451
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
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6304529
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
 
LVL 21

Expert Comment

by:gemarti
ID: 6304653
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
 
LVL 1

Author Comment

by:piscean
ID: 6307399
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
 
LVL 1

Author Comment

by:piscean
ID: 6307407
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:Madshi
ID: 6307409
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
 
LVL 17

Expert Comment

by:inthe
ID: 6307474
>>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
 
LVL 1

Author Comment

by:piscean
ID: 6307719
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
 
LVL 1

Author Comment

by:piscean
ID: 6307722
I mean "The user might be doing something ..."
0
 
LVL 1

Author Comment

by:piscean
ID: 6307762
I mean "The user might be doing something ..."
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6307957
>> 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
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8711211
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
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 8822202
Paq'ed and points not refunded

PashaMod
CS Moderator @Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

19 Experts available now in Live!

Get 1:1 Help Now