Solved

How to change Windows Color Scheme

Posted on 2001-07-20
15
910 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:mnasman
Comment Utility
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:mnasman
Comment Utility
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
Comment Utility
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:mnasman
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
I mean "The user might be doing something ..."
0
 
LVL 1

Author Comment

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

Expert Comment

by:Madshi
Comment Utility
>> 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
Comment Utility
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
Comment Utility
Paq'ed and points not refunded

PashaMod
CS Moderator @Experts Exchange
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

9 Experts available now in Live!

Get 1:1 Help Now