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;
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;