?
Solved

change wallpaper and screensaver

Posted on 2001-07-19
11
Medium Priority
?
491 Views
Last Modified: 2010-07-27
hi there,

how do i change the wallpaper and screensaver at runtime using delphi?

i also need to revert it back to the existing wallpaper and screensaver when my application closes.

how do i do this?

please help. thanks!

gladz
0
Comment
Question by:gladz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 

Expert Comment

by:Rudy_Rai
ID: 6301634
if you want change wallpaper you can use this program

systemparametersinfo(SPI_setdeskwallpaper,0,pchar(edit1.text),spif_sendwininichange);
and in edit1.text, you write your directory file(ex: c:\none.bmp ).
when you close your application set edit1.text became your directory file wallpapers before you change it.

and if you want call screen saver you can use this:
sendmessage(getdesktopwindow,wm_syscommand,sc_screensave,0);
0
 
LVL 2

Expert Comment

by:Felixin
ID: 6302236
Look at

http://www.gnomehome.demon.nl/uddf/index.htm

and search for what you want
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6302696
Hello

  you can change the wallpaper by the SystemParametersInfo api, for the screen saver you need to open the system ini and change it from there, here's a project to change the both of screen saver and the wallpaper, there's a problem with system.ini that it can only use the short file names (8.3 only), so i include the GetShortPathName api to convert the long file name to short file name
 
//===

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
uses inifiles;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pchar('c:\windows\waves.bmp'),
       SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
end;

procedure TForm1.Button2Click(Sender: TObject);
  var
    SysIni : TIniFile;
    s1 : string;
    S2 : array[0..255] of char;
begin
  // convert the long file name to short filename
  s1 := 'c:\windows\system\3d text.scr';
  GetShortPathName(PChar(s1), S2, SizeOf(S2));
// write the new screensaver name to system.ini
  SysIni := TIniFile.Create('c:\windows\system.ini');
  SysIni.WriteString('boot','SCRNSAVE.EXE',S2);
  SysIni.Free;
end;

end.

Best regards
Mohammed Nasman
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6302706
ohh forget to say, button one will convert the wallpaper, and button2 will convert the screen saver
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6302926
Hello

   if the ActiveDesktop is turned on, you can't change the wallpaper in that way, so here's another way to change the wallpaper if you using activedesktop

uses
  comobj, shlobj;
procedure TForm1.Button1Click(Sender: TObject);
const
  CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
var
  ActiveDesktop: IActiveDesktop;
begin
  ActiveDesktop := CreateComObject(CLSID_ActiveDesktop)
    as IActiveDesktop;
  ActiveDesktop.SetWallpaper('c:\winme\CIRCLES.bmp', 0);
  ActiveDesktop.ApplyChanges(AD_APPLY_ALL or AD_APPLY_FORCE);
end;

Best regards
Mohammed
0
 

Expert Comment

by:DelFreak
ID: 6304127
Listening...
0
 

Author Comment

by:gladz
ID: 6306976
mnasman,

I really appreciate your replies. thanks.

But one last thing, how do I revert it back to the original wallpaper and screensaver?

thanks,
gladys
0
 

Author Comment

by:gladz
ID: 6307136
mnasman,

Button 2 does not work properly.  It doesn't change the screensaver when the current setting is NONE.

thanks,
gladys
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6309656
Hello gladys

  if you want to revert to the old screen saver and wallpaper, store them in variables when ur program start, and when your close ur applicatn set them back, it will be like the code above, but pass the old value that u stored in the varibles

 I forget to include API to inform the windows about screensaver, add this line in the button 2
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,0,1);
this will set the screeen saver active, now the code will be like this

procedure TForm1.Button2Click(Sender: TObject);
  var
    SysIni : TIniFile;
    s1 : string;
    S2 : array[0..255] of char;
begin
  // convert the long file name to short filename
  s1 := 'c:\winme\system\3d text.scr';
  GetShortPathName(PChar(s1), S2, SizeOf(S2));
// write the new screensaver name to system.ini
  SysIni := TIniFile.Create('c:\winme\system.ini');
  SysIni.WriteString('boot','SCRNSAVE.EXE',S2);
  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,0,1);
  SysIni.Free;
End;

Mohammed
0
 

Author Comment

by:gladz
ID: 6310854
mnasman,

Thanks. :)

Another thing though....
An error occurs when I check for ActiveDesktop - 'Class not registered'

About the thing on getting the existing wallpaper and screensaver, I'm asking about the exact command set? What is the syntax?

Thanks again,
Gladys
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 900 total points
ID: 6368850
gladz

  here's the full sample, that will change the wallpaper and screen saver when u run ur program, and will restore the them after ur close ur program
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  OldWallPaper,OldScreeSaver : String;
implementation

{$R *.DFM}
uses Registry,IniFiles;
procedure TForm1.FormCreate(Sender: TObject);
var
   SysIni : TIniFile;
   s1 : string;
   S2 : array[0..255] of char;
begin
  // read the cureen screen saver
  SysIni := TIniFile.Create('c:\windows\system.ini');
  OldScreeSaver := SysIni.ReadString('boot','SCRNSAVE.EXE','');
  // convert the long file name to short filename
  s1 := 'c:\windows\system\3d text.scr';
  GetShortPathName(PChar(s1), S2, SizeOf(S2));
 // write the new screensaver name to system.ini
  SysIni.WriteString('boot','SCRNSAVE.EXE',S2);
  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,0,1);
  SysIni.Free;
//=========== this section to read the current wallpaper
  SysIni := TIniFile.Create('c:\windows\win.ini');
  OldWallPaper := SysIni.ReadString('Desktop','Wallpaper','');
  ShowMessage(OldWallPaper);
// change it to which one u want to use
  SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pchar('c:\windows\tiles.bmp'),
      SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE);
  SysIni.Free;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
   SysIni : TIniFile;
   s1 : string;
begin
  // write the old screensaver
  SysIni := TIniFile.Create('c:\windows\system.ini');
  SysIni.WriteString('boot','SCRNSAVE.EXE',OldScreeSaver);
  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,1,0,1);
  SysIni.Free;
// write the old wallpaper
  SysIni := TIniFile.Create('c:\windows\win.ini');
  SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pchar(OldWallPaper),
      SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE);
  SysIni.Free;
end;


end.

Best regards
Mohammed Nasman
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 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