gladz
asked on
change wallpaper and screensaver
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
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
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_S ETDESKWALL PAPER, 0, pchar('c:\windows\waves.bm p'),
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:\window s\system.i ni');
SysIni.WriteString('boot', 'SCRNSAVE. EXE',S2);
SysIni.Free;
end;
end.
Best regards
Mohammed Nasman
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
begin
SystemParametersInfo(SPI_S
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
end;
procedure TForm1.Button2Click(Sender
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)
// write the new screensaver name to system.ini
SysIni := TIniFile.Create('c:\window
SysIni.WriteString('boot',
SysIni.Free;
end;
end.
Best regards
Mohammed Nasman
ohh forget to say, button one will convert the wallpaper, and button2 will convert the screen saver
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- 006097DEAC F9}';
var
ActiveDesktop: IActiveDesktop;
begin
ActiveDesktop := CreateComObject(CLSID_Acti veDesktop)
as IActiveDesktop;
ActiveDesktop.SetWallpaper ('c:\winme \CIRCLES.b mp', 0);
ActiveDesktop.ApplyChanges (AD_APPLY_ ALL or AD_APPLY_FORCE);
end;
Best regards
Mohammed
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
const
CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-
var
ActiveDesktop: IActiveDesktop;
begin
ActiveDesktop := CreateComObject(CLSID_Acti
as IActiveDesktop;
ActiveDesktop.SetWallpaper
ActiveDesktop.ApplyChanges
end;
Best regards
Mohammed
Listening...
ASKER
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
I really appreciate your replies. thanks.
But one last thing, how do I revert it back to the original wallpaper and screensaver?
thanks,
gladys
ASKER
mnasman,
Button 2 does not work properly. It doesn't change the screensaver when the current setting is NONE.
thanks,
gladys
Button 2 does not work properly. It doesn't change the screensaver when the current setting is NONE.
thanks,
gladys
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_S ETSCREENSA VEACTIVE,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_S ETSCREENSA VEACTIVE,1 ,0,1);
SysIni.Free;
End;
Mohammed
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_S
this will set the screeen saver active, now the code will be like this
procedure TForm1.Button2Click(Sender
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)
// write the new screensaver name to system.ini
SysIni := TIniFile.Create('c:\winme\
SysIni.WriteString('boot',
SystemParametersInfo(SPI_S
SysIni.Free;
End;
Mohammed
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
systemparametersinfo(SPI_s
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(getdesktopwind