Solved

SystemParametersInfo

Posted on 1998-09-13
9
878 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
LAN or WAN ? 11 95
Dynamically Created Query 3 62
I want to use librsync in my Delphi backup application. 3 58
Microsoft Access 97 and Delphi XE2 9 53
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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