Solved

SystemParametersInfo

Posted on 1998-09-13
9
881 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:poc3796
[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
  • 4
  • 4
9 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1339593
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.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339594
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);

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339595
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
0
Technology Partners: 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!

 

Author Comment

by:poc3796
ID: 1339596
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 .....
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339597
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
0
 

Author Comment

by:poc3796
ID: 1339598
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
0
 

Author Comment

by:poc3796
ID: 1339599
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
0
 

Author Comment

by:poc3796
ID: 1339600
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
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1339601
Hello..Here is the full coding........
---------------
uses registry;
procedure SetWallPaper(sWallpaperBMPPath : String; bTile : Boolean);
var
  Reg : TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    Reg.OpenKey('\Control Panel\Desktop', False);
    Reg.WriteString('Wallpaper', sWallpaperBMPPath);
    Reg.WriteString('TileWallpaper', IntToStr(Word(bTile)));
  finally
    reg.CloseKey;
    Reg.Free;
  end;
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Nil,
      SPIF_SENDWININICHANGE);
end;
procedure TForm1.PNLButton1Click(Sender: TObject);
begin
  SetWallpaper('C:\windows\Forest.bmp', False);
end;
---------------
Regards,
Viktor Ivanov
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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