Link to home
Start Free TrialLog in
Avatar of poc3796
poc3796

asked on

SystemParametersInfo

I write a program that change windows desktop using
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, 0, Pchar('Bitmap.Bmp'), SPIF_SENDWININICHANGE)
This work when I execute the program from Delphi IDE but if I execute it from menu this return ErrorCode 2
Avatar of Madshi
Madshi

Have you tried 'c:\windows\bitmap.bmp'?
ErrorCode=2 means "File not found" or something like that, I think. But I'm not sure.

Regards, Madshi.
Try this......
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, 0,   Pchar('C:\windows\desktop\YourFolder\Bitmap.Bmp'),
     SPIF_SENDWININICHANGE);

if it still isn't working try this.....
  SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, 0,       Pointer('C:\windows\desktop\YourFolder\Bitmap.Bmp'),
     SPIF_SENDWININICHANGE);

If you have saved the project and the bitmap is in your folder then you can use Bitmap.bmp
if you haven't saved the project and you are trying to do Bitmap.bmp it is looking in the Delphi folder and isn't finding the bitmap...so you need to extended and give the exact path to the bitmap.....

Regards,
Viktor Ivanov
Avatar of poc3796

ASKER

with Pointer cluase the program is not compiled, and the strange thing is that
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Pchar('Bitmap.Bmp'), SPIF_SENDWININICHANGE)
WORK in IDE .....
Why don't you try this........
---------------------
uses Windows, registry;
procedure SetWallPaper(sWallpaperBMPPath : String; bTile : Boolean);
var
  reg : TRegIniFile;
begin
  reg : TRegIniFile.Create('Control Panel\Dekstop');
  with reg do
  begin
    WriteString('', 'Wallpaper', sWallpaperBMPPath);
    if bTile then
    begin
      WriteString('', 'TileWallpaper', '1');
    end
    else
    begin
      WriteString('', 'TileWallpaper', '0');
    end;
  end;
  reg.Free;
  SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Nil, SPIF_SENDWININICHANGE);
end;

Example Call : SetWallpaper('C:\Windows\desktop\MyBitmap.bmp', False);
--------------
Regards,
Viktor Ivanov
Avatar of poc3796

ASKER

I drag & drop your procedure in my program but this don't work also in IDE [but this is compiled].

I try this:

procedure TForm1.Button1Click(Sender: TObject);
var cString: String;
begin
    cString := 'D:\temp\sfondo2.BMP';
    if FileExists( cString ) then
        if not( SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, Pchar( cString ), SPIF_SENDWININICHANGE) ) then
            MessageBox( 0, PChar( Format( '%d', [GetLastError()] )), 'Errore', MB_OKCANCEL + MB_DEFBUTTON1);
end;

procedure TForm1.Button2Click(Sender: TObject);
var cString: String;
begin
    SetWallPaper( 'D:\DOWNLOAD\SFONDI~1\manab0~1.BMP', False );
end;

// *--------------------------------------------------------------------------
procedure SetWallPaper(sWallpaperBMPPath : String; bTile : Boolean);
var
  reg : TRegIniFile;
begin
  reg := TRegIniFile.Create('Control Panel\Dekstop');
  with reg do
  begin
    WriteString('', 'Wallpaper', sWallpaperBMPPath);
    if bTile then
    begin
      WriteString('', 'TileWallpaper', '1');
    end
    else
    begin
      WriteString('', 'TileWallpaper', '0');
    end;
  end;
  reg.Free;
  SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Nil, SPIF_SENDWININICHANGE);
end;

Bottom1Click work in IDE evironment
Bottom2Click don't work at all

regards
poc3796
Avatar of poc3796

ASKER

Excuse me in the fast try that I do I don't see that you write DEKSTOP other than DESKTOP when I correct your code work well

Repost an answer and I accept it

Excuse me
Avatar of poc3796

ASKER

Excuse me in the fast try that I do I don't see that you write DEKSTOP other than DESKTOP when I correct your code work well

Repost an answer and I accept it

Excuse me
ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial