How to Change the Desktop Wallpaper

The desktop wallpaper can be set by editing a few entries in the system registry but this will not let Windows know that it has been changed. Also you should make a call to the SystemParametersInfo() function.
You can use BMP, GIF of JPEG images for the wallpaper but GIF and JPEG images will only be shown if the ActiveDesktop (Internet Explorer 4+) if set active.

  uses
    Registry, WinProcs;
  ...
  procedure SetWallaper(sNewWallpaper: string; bTile: Boolean);
  begin
    with TRegistry.Create do
      try
        OpenKey('Control PanelDesktop', True);
        WriteString('Wallpaper', sNewWallpaper);
        if bTile then
          WriteString('TileWallpaper', '1')
        else
          WriteString('TileWallpaper', '0');
        CloseKey;
      finally
        Free;
      end;

    { Let Windows know that we changed a system parameter }
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(sNewWallpaper), SPIF_SENDWININICHANGE);
  end;

Example:

  { Sets wallpaper to centered setup.bmp }
  SetWallpaper('C:Windowssetup.bmp', False);

Tags: , , , , , , , ,

No Comments Yet

You can be the first to comment!

Leave a comment

OpenID Login

Standard Login