Month: January 2016

Setting WallPaper with Win32 / Windows 10

Posted on Updated on

Since Win10, some behavior modification : using ‘SystemParametersInfo‘,

file path must be absolute, so :

SPI_SETDESKWALLPAPER = 20
SPIF_UPDATEINIFILE = 0x1
SPIF_SENDWININICHANGE = 0x2
$systemParametersInfo = Win32API.new(‘user32′,’SystemParametersInfo’, [‘I’,’I’,’P’,’I’], ‘I’)

def setwp(img)
img2=Dir.pwd.gsub(“/”,”\\”)+”\\”+img
$systemParametersInfo.call(SPI_SETDESKWALLPAPER, 0, img2,  SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)
end

For tuning wallparper position, there are no API, only registry set , see msn doc ,  tab Description => paragraph “Implementation”.
TileWallpaper
0: The wallpaper picture should not be tiled
1: The wallpaper picture should be tiled

WallpaperStyle
0:  The image is centered if TileWallpaper=0 or tiled if TileWallpaper=1
2:  The image is stretched to fill the screen
6:  The image is resized to fit the screen while maintaining the aspect
ratio. (Windows 7 and later)
10: The image is resized and cropped to fill the screen while maintaining
the aspect ratio. (Windows 7 and later)