Beranda > Delphi > Setting the wallpaper (tiled, centered, stretched, or positioned)

Setting the wallpaper (tiled, centered, stretched, or positioned)

This function will set a BMP of your choice as the wallpaper for Windows and you can set it as tiled, stretched, centered, or positioned anywhere on screen. Works on all 32-bit Windows platforms. This procedure should now work with the Active Desktop option turned on.uses
  Registry;

const
  { WallPaperStyles }
  WPS_Tile = 0;
  WPS_Center = 1;
  WPS_Stretch = 2;
  WPS_XY = 3;

procedure SetWallpaperExt(sWallpaperBMPPath: string; nStyle, nX, nY: integer);
{ sWallpaperBMPPath                  }
{ – path to a BMP file               }
{                                    }
{ nStyle                             }
{ – any of the above WallPaperStyles }
{                                    }
{ nX, nY                             }
{ – if the nStyle is set to WPS_XY,  }
{ nX and nY can be used to set the   }
{ exact position of the wall paper,  }
{ otherwise specify 0 for both.      }
var
  reg : TRegIniFile;
  s1  : string;
  X, Y: integer;
begin
  { change registry:          }
  {                           }
  { HKEY_CURRENT_USER\        }
  { Control Panel\Desktop     }
  { TileWallpaper (REG_SZ)    }
  { Wallpaper (REG_SZ)        }
  { WallpaperStyle (REG_SZ)   }
  { WallpaperOriginX (REG_SZ) }
  { WallpaperOriginY (REG_SZ) }

  Reg := TRegIniFile.Create(‘Control Panel\Desktop’);
  try
    with Reg do
      begin
        s1 := ‘0’;
        X  := 0;
        Y  := 0;

        case nStyle of
          WPS_Tile  : s1 := ‘1’;
          WPS_Center: nStyle := WPS_Tile;
          WPS_XY    :
            begin
              nStyle := WPS_Tile;
              X := nX;
              Y := nY;
            end;
        end;

        WriteString(”, ‘Wallpaper’, sWallpaperBMPPath);
        WriteString(”, ‘TileWallpaper’, s1);
        WriteString(”, ‘WallpaperStyle’, IntToStr(nStyle));
        WriteString(”, ‘WallpaperOriginX’, IntToStr(X));
        WriteString(”, ‘WallpaperOriginY’, IntToStr(Y));
      end;
  finally
    Reg.Free;
  end;

  { let Windows know that we }
  { changed a system parameter }
  SystemParametersInfo(SPI_SETDESKWALLPAPER, 1, PChar(sWallpaperBMPPath), SPIF_UPDATEINIFILE or
SPIF_SENDWININICHANGE);

end;

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: