Solved

SystemParametersInfo

Posted on 1998-09-13
9
875 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now