Solved

SystemParametersInfo

Posted on 1998-09-13
9
886 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month6 days, 22 hours left to enroll

623 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