Jump to content

Download and change wallpaper


Recommended Posts

I tried this script but i get errors

#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()

InetGet("http://mattys-stuff.uboxi.com/s.bmp", @TempDir & "\s.bmp")
WallpaperSet(@TempDir&"\s.bmp",$WALLPAPER_STRETCH)

ChangeDesktopWallPaper(@TempDir & '\' & 's.bmp',1)
>"C:\Users\Matthew\Desktop\install\SciTe\..\autoit3.exe" /ErrorStdOut "C:\Users\Matthew\Desktop\install\wallpapachange.au3"    
"C:\Users\Matthew\Desktop\install\wallpapachange.au3" (108) : ==> Variable used without being declared.:
WallpaperSet(@TempDir&"\s.bmp",$WALLPAPER_STRETCH)
WallpaperSet(@TempDir&"\s.bmp",^ ERROR
>Exit code: 1    Time: 2.259

 

Link to comment
Share on other sites

Declared undeclared var at start of script . Look for the <------------------------------------------ on lien 5

Did not test.

#include <WinAPI.au3>
#include <File.au3>
#include <GDIPlus.au3>

Local $WALLPAPER_STRETCH  ;<---------------------- Declared variable here
#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()

InetGet("http://mattys-stuff.uboxi.com/s.bmp", @TempDir & "\s.bmp")
WallpaperSet(@TempDir&"\s.bmp",$WALLPAPER_STRETCH)

ChangeDesktopWallPaper(@TempDir & '\' & 's.bmp',1)

 

MEASURE TWICE - CUT ONCE

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...