eri Posted February 2, 2010 Share Posted February 2, 2010 How to change Wallpaper with Autoit In windows XP? I found this Topic http://www.autoitscript.com/forum/index.php?showtopic=52117&st=0&p=441481&hl=change%20wallpaper%20xp&fromsearch=1&#entry441481 But when run script Error in A3LGDIPlus.au3 and _GDIP_Startup() And Where I can download autoit library..?? Please help me.. From Newbe.. Link to comment Share on other sites More sharing options...
Bert Posted February 2, 2010 Share Posted February 2, 2010 expandcollapse popup#include <WinAPI.au3> #include <File.au3> #include <GDIPlus.au3> #Region WallpaperSet() ; =================================================================== ; WallpaperSet($sPath, $nStyle = $WALLPAPER_STRETCH, $sConversionPath = "") ; ; Sets the desktop wallpaper to the specified file. ; Parameters: ; $sPath - IN - The path to the wallpaper file. If this file is not a BMP then it will be converted ; to a BMP at either $sConversionPath (if present) or an auto-generated location. ; $nStyle - IN/OPTIONAL - Controls the display of the wallpaper using the $WALLPAPER_* flags. ; $sConversionPath - IN/OPTIONAL - The path to save a BMP wallpaper when one is generated from ; a non-BMP wallpaper. ; Returns: ; Success - Returns True. ; Failure - Returns False and sets @error to non-zero. ; =================================================================== Func WallpaperSet($sPath, $nStyle = $WALLPAPER_STRETCH, $sConversionPath = "") ; Ensure the file exists. Allows an empty path which clears the wallpaper. If $sPath And Not FileExists($sPath) Then Return SetError(1, 0, False) ; Split the path. Local $sDrive, $sDir, $sFile, $sExt _PathSplit($sPath, $sDrive, $sDir, $sFile, $sExt) ; Convert the image to a bitmap. If $sPath And $sExt <> ".bmp" Then ; Startup GDI Plus. If Not _GDIPlus_Startup () Then Return SetError(2, 0, False) ; Declare variables that are used inside and outside the loop. Local $hImage, $nError, $nExtended ; Pseudo-loop so that cleanup will always happen. Do ; Load the image in it's original format. $hImage = _GDIPlus_ImageLoadFromFile($sPath) If $hImage = -1 Then $nError = 3 ExitLoop EndIf ; Get the Bitmap converter CLSID. Local $sCLSID = _GDIPlus_EncodersGetCLSID ("BMP") If Not $sCLSID Then $nError = 4 ExitLoop EndIf ; If the conversion path isn't specified generate one from the input file. If Not $sConversionPath Then $sConversionPath = _PathMake($sDrive, $sDir, $sFile, ".bmp") ; Change the input path to the converted path. $sPath = $sConversionPath ; Save the output file to the new path. If Not _GDIPlus_ImageSaveToFileEx($hImage, $sPath, $sCLSID) Then $nError = 5 ExitLoop EndIf Until True ; Release the image. _GDIPlus_ImageDispose($hImage) ; Shutdown GDI Plus. _GDIPlus_ShutDown() ; Abort if an error occurred in the loop. If $nError Then Return SetError($nError, $nExtended, False) EndIf ; Constant for the registry key where the wallpaper information is stored. Local Const $sRegKey = "HKEY_CURRENT_USER\Control Panel\Desktop" ; Tiling and centering/stretching are handled by two separate keys. If ; tiling then the style needs set to 0 and tile needs set to 1. Otherwise ; tile needs set to 0 and the style needs set to either 0 or 2. If $nStyle = $WALLPAPER_TILE Then RegWrite($sRegKey, "TileWallPaper", "REG_SZ", 1) RegWrite($sRegKey, "WallpaperStyle", "REG_SZ", 0) Else RegWrite($sRegKey, "TileWallPaper", "REG_SZ", 0) RegWrite($sRegKey, "WallpaperStyle", "REG_SZ", $nStyle) EndIf ; Constants for SystemParametersInfo(). Local $SPI_SETDESKWALLPAPER = 20 Local $SPIF_UPDATEINIFILE = 1 Local $SPIF_SENDCHANGE = 2 ; Create a structure to hold the path string. Local $vPath = DllStructCreate("wchar[" & StringLen($sPath) + 1 & "]") DllStructSetData($vPath, 1, $sPath) ; Update the wallpaper. Local $bResult = _WinAPI_SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, DllStructGetPtr($vPath), BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) ; Ensure the update was successful. If not set @error to a unique value. If Not $bResult Then Return SetError(6, 0, $bResult) Return $bResult EndFunc ; WallpaperSet() #EndRegion WallpaperSet() The Vollatran project  My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
eri Posted February 2, 2010 Author Share Posted February 2, 2010 That`s very complex for me.. Can you explain how to use it. I have a picture in desktop. The File Image name is SampleDesktop.bmp How to set my sample Image to Your Script..?? Link to comment Share on other sites More sharing options...
james3mg Posted February 2, 2010 Share Posted February 2, 2010 Welcome to the forums What Volly gave you is a function- you don't have to modify it at all, just copy the #include lines at the top into the top of your script, and the function (the rest of what he posted) to the bottom of your script. Then you call the function, providing it at least the full path of the file you want to set as your wallpaper: WallpaperSet(@DesktopDir&"\SampleDesktop.bmp") You might want to play with the second option as well: it allows you to specify if the wallpaper is stretched, tiled, etc. For instance: WallpaperSet(@DesktopDir&"\SampleDesktop.bmp",$WALLPAPER_STRETCH)will explicitly tell Windows that it should stretch the image you specify to fit the whole desktop. Give it a shot, and post back codes that you've tried if you need more help. "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
eri Posted February 3, 2010 Author Share Posted February 3, 2010 Thank`s James.. i have tried script.. expandcollapse popup#include <WinAPI.au3> #include <File.au3> #include <GDIPlus.au3> WallpaperSet(@DesktopDir&"\SampleDesktop.bmp") #Region WallpaperSet() ; =================================================================== ; WallpaperSet($sPath, $nStyle = $WALLPAPER_STRETCH, $sConversionPath = "") ; ; Sets the desktop wallpaper to the specified file. ; Parameters: ; $sPath - IN - The path to the wallpaper file. If this file is not a BMP then it will be converted ; to a BMP at either $sConversionPath (if present) or an auto-generated location. ; $nStyle - IN/OPTIONAL - Controls the display of the wallpaper using the $WALLPAPER_* flags. ; $sConversionPath - IN/OPTIONAL - The path to save a BMP wallpaper when one is generated from ; a non-BMP wallpaper. ; Returns: ; Success - Returns True. ; Failure - Returns False and sets @error to non-zero. ; =================================================================== Func WallpaperSet($sPath, $nStyle = $WALLPAPER_STRETCH, $sConversionPath = "") ; Ensure the file exists. Allows an empty path which clears the wallpaper. If $sPath And Not FileExists($sPath) Then Return SetError(1, 0, False) ; Split the path. Local $sDrive, $sDir, $sFile, $sExt _PathSplit($sPath, $sDrive, $sDir, $sFile, $sExt) ; Convert the image to a bitmap. If $sPath And $sExt <> ".bmp" Then ; Startup GDI Plus. If Not _GDIPlus_Startup () Then Return SetError(2, 0, False) ; Declare variables that are used inside and outside the loop. Local $hImage, $nError, $nExtended ; Pseudo-loop so that cleanup will always happen. Do ; Load the image in it's original format. $hImage = _GDIPlus_ImageLoadFromFile($sPath) If $hImage = -1 Then $nError = 3 ExitLoop EndIf ; Get the Bitmap converter CLSID. Local $sCLSID = _GDIPlus_EncodersGetCLSID ("BMP") If Not $sCLSID Then $nError = 4 ExitLoop EndIf ; If the conversion path isn't specified generate one from the input file. If Not $sConversionPath Then $sConversionPath = _PathMake($sDrive, $sDir, $sFile, ".bmp") ; Change the input path to the converted path. $sPath = $sConversionPath ; Save the output file to the new path. If Not _GDIPlus_ImageSaveToFileEx($hImage, $sPath, $sCLSID) Then $nError = 5 ExitLoop EndIf Until True ; Release the image. _GDIPlus_ImageDispose($hImage) ; Shutdown GDI Plus. _GDIPlus_ShutDown() ; Abort if an error occurred in the loop. If $nError Then Return SetError($nError, $nExtended, False) EndIf ; Constant for the registry key where the wallpaper information is stored. Local Const $sRegKey = "HKEY_CURRENT_USER\Control Panel\Desktop" ; Tiling and centering/stretching are handled by two separate keys. If ; tiling then the style needs set to 0 and tile needs set to 1. Otherwise ; tile needs set to 0 and the style needs set to either 0 or 2. If $nStyle = $WALLPAPER_TILE Then RegWrite($sRegKey, "TileWallPaper", "REG_SZ", 1) RegWrite($sRegKey, "WallpaperStyle", "REG_SZ", 0) Else RegWrite($sRegKey, "TileWallPaper", "REG_SZ", 0) RegWrite($sRegKey, "WallpaperStyle", "REG_SZ", $nStyle) EndIf ; Constants for SystemParametersInfo(). Local $SPI_SETDESKWALLPAPER = 20 Local $SPIF_UPDATEINIFILE = 1 Local $SPIF_SENDCHANGE = 2 ; Create a structure to hold the path string. Local $vPath = DllStructCreate("wchar[" & StringLen($sPath) + 1 & "]") DllStructSetData($vPath, 1, $sPath) ; Update the wallpaper. Local $bResult = _WinAPI_SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, DllStructGetPtr($vPath), BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) ; Ensure the update was successful. If not set @error to a unique value. If Not $bResult Then Return SetError(6, 0, $bResult) Return $bResult EndFunc ; WallpaperSet() #EndRegion WallpaperSet() But get error.. : wallpaperset(@DesktopDir&"\sampleDesktop.bmp") wallpaperset(@DesktopDir&"\sampleDes^ERROR Error:Variable used without being declared. Can U give me another solution.. Thank`s.. Link to comment Share on other sites More sharing options...
eri Posted February 4, 2010 Author Share Posted February 4, 2010 Hi.. Please Help this Topic.. Link to comment Share on other sites More sharing options...
omikron48 Posted February 4, 2010 Share Posted February 4, 2010 (edited) Just set these variables before the function definitions. You can also use them to set the second parameter to make your wallpaper centered, tiled or stretched. Global $WALLPAPER_CENTER = 0 Global $WALLPAPER_TILE = 1 Global $WALLPAPER_STRETCH = 2 Edited February 4, 2010 by omikron48 Link to comment Share on other sites More sharing options...
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