dantay9 Posted March 21, 2009 Posted March 21, 2009 (edited) This has already been made, but I think this one is more universal and easier to understand.Change Wallpaper.au3 Edited November 28, 2009 by dantay9
dmob Posted March 23, 2009 Posted March 23, 2009 (edited) This has already been made, but I think this one is more universal. expandcollapse popupFunc ChangeWallpaper($FileLong, $State = 3) Local $String = $FileLong, $SPI_SETDESKWALLPAPER = 20, $SPIF_UPDATEINIFILE = 1, $SPIF_SENDCHANGE = 2 Do $FileLong = $String $String = StringReplace($FileLong, "/", "\") Until @extended = 0 If Not FileExists($FileLong) Then SetError(-1) Return 0 EndIf If StringRight($FileLong, 3) <> "bmp" Then SetError(-2) Return 0 EndIf Local $WDir = RegRead('HKLM\Software\Microsoft\Windows\CurrentVersion', 'WallPaperDir') $FileShort = StringSplit($FileLong, "\") $FileShort = $FileShort[$FileShort[0]] If StringInStr($WDir, '%SystemRoot%') <> 0 Then $WDir = StringTrimLeft($WDir, 12) $WDir = @WindowsDir & $WDir EndIf FileCopy($FileLong, $WDir, 1); make wallpaper available in desktop properties window FileCopy($FileLong, 'C:\Documents and Settings\Owner\Local Settings\Application Data\Microsoft\Wallpaper1.bmp', 1) RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', 'C:\Documents and Settings\Owner\Local Settings\Application Data\Microsoft\Wallpaper1.bmp') RegWrite('HKCU\Control Panel\Desktop', 'ConvertedWallpaper', 'reg_sz', $WDir & "\" & $FileShort) Select Case 1; centered RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0') RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0') Case 2; tiled RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '1') RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0') Case 3; stretched RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0') RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '2') Case Else EndSelect $Dll = DllCall("user32.dll", "int", "SystemParametersInfo", _ "int", $SPI_SETDESKWALLPAPER, _ "int", 0, _ "str", $FileLong, _ "int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) EndFunc;==>ChangeWallpaper The Select structure is incomplete. Did you mean Select $State? What do you mean Universal? Edited March 23, 2009 by dmob
ghetek Posted March 23, 2009 Posted March 23, 2009 (edited) update. expandcollapse popupFunc ChangeWallpaper($FileLong, $State = 3) Local $String = $FileLong, $SPI_SETDESKWALLPAPER = 20, $SPIF_UPDATEINIFILE = 1, $SPIF_SENDCHANGE = 2 Do $FileLong = $String $String = StringReplace($FileLong, "/", "\") Until @extended = 0 If Not FileExists($FileLong) Then SetError(-1) Return 0 EndIf If StringRight($FileLong, 3) <> "bmp" Then SetError(-2) Return 0 EndIf Local $WDir = RegRead('HKLM\Software\Microsoft\Windows\CurrentVersion', 'WallPaperDir') $FileShort = StringSplit($FileLong, "\") $FileShort = $FileShort[$FileShort[0]] If StringInStr($WDir, @WindowsDir) <> 0 Then $WDir = StringTrimLeft($WDir, 12) $WDir = @WindowsDir & $WDir EndIf FileCopy($FileLong, $WDir, 1); make wallpaper available in desktop properties window FileCopy($FileLong, @UserProfileDir & '\Local Settings\Application Data\Microsoft\Wallpaper1.bmp', 1) RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', @UserProfileDir & '\Local Settings\Application Data\Microsoft\Wallpaper1.bmp') RegWrite('HKCU\Control Panel\Desktop', 'ConvertedWallpaper', 'reg_sz', $WDir & "\" & $FileShort) Switch $State Case 1; centered RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0') RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0') Case 2; tiled RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '1') RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0') Case 3; stretched RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0') RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '2') Case Else EndSwitch $Dll = DllCall("user32.dll", "int", "SystemParametersInfo", _ "int", $SPI_SETDESKWALLPAPER, _ "int", 0, _ "str", $FileLong, _ "int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) EndFunc;==>ChangeWallpaper Edited March 23, 2009 by ghetek
dantay9 Posted March 23, 2009 Author Posted March 23, 2009 Oh. Thanks for fixing that ghetek. Simple mistake.
mrmacadamia Posted May 16, 2009 Posted May 16, 2009 Oh. Thanks for fixing that ghetek. Simple mistake.i can't seem to get it work..how do i get it work?
mrmacadamia Posted May 21, 2009 Posted May 21, 2009 i can't seem to get it work..how do i get it work?ouh i got it now...thanks
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now