08-08-2009, 07:23 AM
Correct. Should work if it is bmp. Fails if jpg.
This is better version. Supports center/tile/stretch. Throws error if fails. Does not remove wallpaper if fails.
Function SetWallpaper
This is better version. Supports center/tile/stretch. Throws error if fails. Does not remove wallpaper if fails.
Function SetWallpaper
;/
function $wpFile [style] ;;style: 0 center, 1 tile, 2 stretch, 3 fit (Win7), 4 fill (Win7)
;Sets desktop wallpaper.
;wpFile - bmp file.
;;;Error if does not exist or is not bmp (Vista/7 also supports jpg).
;;;Use "" to remove wallpaper.
if(!empty(wpFile))
,wpFile=_s.searchpath(wpFile)
,if(!wpFile) end "file does not exist"
lpstr rk="control panel\desktop"
;get current values to restore if fails
str _wp _tw _ws
rget _wp "wallpaper" rk; rget _tw "tilewallpaper" rk; rget _ws "wallpaperstyle" rk
;set style
lpstr rstyle("0") rtile("0")
sel style&255
,case 1 rtile="1"
,case 2 rstyle="2"
,case 3 if(_winver>=0x601) rstyle="6"
,case 4 if(_winver>=0x601) rstyle="10"
rset rstyle "wallpaperstyle" rk; rset rtile "tilewallpaper" rk
;set file
if !SystemParametersInfo(SPI_SETDESKWALLPAPER 0 wpFile 3)
,;when SPI fails, it removes wallpaper. Restore.
,rset _tw "tilewallpaper" rk; rset _ws "wallpaperstyle" rk
,SystemParametersInfo(SPI_SETDESKWALLPAPER 0 _wp 3)
,end ES_FAILED