Jump to content

Windows Wallpaper Changer


Don N
 Share

Recommended Posts

I saw someone talking about this in the Idea Lab section and thought itd be pretty cool so ehres the basic one now. Works on Windows XP, needs beta and needs the file in the same dir as the script/exe.

Let me know what you think/ideas for additions to script/anybugs you encounter

The script is attached here:

wallpaper_changer.au3

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

this is neat i added a file select dialog to it :D

#include <GUIConstants.au3>

;Constants used in the Dll call

Dim Const $SPI_SETDESKWALLPAPER = 20;
Dim Const $SPIF_UPDATEINIFILE = 0x01;
Dim Const $SPIF_SENDWININICHANGE = 0x02;
Dim Const $REGISTRY_PATH = "HKEY_CURRENT_USER\Control Panel\Desktop"

;create the gui
$wall_change = GUICreate( "Don's Wallpaper Changer",300, 300 )

;create a simple about message for the script
GUICtrlCreateGroup( "What this does...", 15, 15, 270, 55 )
GUICtrlCreateLabel( "This program allows you to easily change the picture and style of your wallpaper.", 20, 30, 260, 30 )
GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group

; now that the GUI is created, show the gui and await user interaction
GUISetState(@SW_SHOW)

GUICtrlCreateGroup( "Image name( must be *.bmp ): ", 15, 75, 270, 50 )
$file_name = GUICtrlCreateInput( "", 20, 95, 180, 20 )
$Select = GUICtrlCreateButton("Select", 205, 93, 75, 25)
GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group

GUICtrlCreateGroup( "Wallpaper Options: ", 15, 135, 270, 110 )
$tile = GUICtrlCreateRadio( "Tile", 30, 155, 240, 20 )
$center = GUICtrlCreateRadio( "Center", 30, 185, 240, 20 )
$stretch = GUICtrlCreateRadio( "Stretch", 30, 215, 240, 20 )
GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group

$change = GUICtrlCreateButton( "Change Wallpaper", 100, 255, 100, 30 )

;set the default to center
GUICtrlSetState ($center, $GUI_CHECKED)

While 1
    $msg = GuiGetMsg()
    
    Select
    
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Select
        ;select the image to be background
        $Dialog= FileOpenDialog('Select Background picture',@DesktopDir,'(*.bmp)')
        GUICtrlSetData($file_name,$Dialog)
        
    Case $msg = $change
        ;check to make sure that a file name was supplied
        $file_path = GUICtrlRead( $file_name )
        
        If $file_path = "" Then
            MsgBox( 4096, "Error!!!", "Please enter a valid file name!" )
        EndIf
        
        ;now make sure the .bmp extension is on the image name, if not, add it
        If StringRight( $file_path, 4 ) <> ".bmp" Then
            $file_path &= ".bmp"
        EndIf
        
        If Not StringInStr( $file_path, @WorkingDir ) Then
            $file_path = @WorkingDir & "\" & $file_path
            GUICtrlSetData( $file_name, $file_path )
        EndIf
        
        ;now that the file name is valid, try to locate the file in the script directory
        If FileExists( $file_path ) Then
                ;now that we knwo the file exists, start making changes
                ;first update the wallpaper style in the registry
                
                ;used to check for DllCall and RegWrite errors
                Local $err
                
                ;Set tiled
                If BitAND(GUICtrlRead($tile), $GUI_CHECKED) = $GUI_CHECKED Then
                    $err = RegWrite( $REGISTRY_PATH, "WallpaperStyle", "REG_SZ", "1" )
                    $err += RegWrite( $REGISTRY_PATH, "TileWallpaper", "REG_SZ", "1" )
                ;Set centered
                ElseIf BitAND(GUICtrlRead($center), $GUI_CHECKED) = $GUI_CHECKED Then
                    $err = RegWrite( $REGISTRY_PATH, "WallpaperStyle", "REG_SZ", "1" )
                    $err += RegWrite( $REGISTRY_PATH, "TileWallpaper", "REG_SZ", "0" )                    
                ;Set stretched
                Else
                    $err = RegWrite( $REGISTRY_PATH, "WallpaperStyle", "REG_SZ", "2" )
                    $err += RegWrite( $REGISTRY_PATH, "TileWallpaper", "REG_SZ", "0" )                
                EndIf
            
                ;Now that the registry edits were attempted, check for any errors
                If $err <> 2 Then
                    MsgBox( 4096, "Registery Error!!!", "There was an error writing to the registry." )
                Else
                    ;No error writing to the registry, make the Dll call to change the image!
                    $err = DllCall( "User32.dll", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, _
                                    "int", 0, "string", $file_path, "int", $SPIF_UPDATEINIFILE )
                    If @error <> 0 Then
                        MsgBox( 4096, "Dll Error!!!", "There was an error making the Dll call." & @CR & "Error Code: " & @error )
                    EndIf 
                    $err = DllCall( "User32.dll", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, _
                                    "int", 0, "string", $file_path, "int", $SPIF_SENDWININICHANGE )
                    If @error <> 0 Then
                        MsgBox( 4096, "Dll Error!!!", "There was an error making the Dll call." & @CR & "Error Code: " & @error )
                    EndIf                      
                EndIf
        Else
            MsgBox( 4096, "Error!!!", "The file was not found in the current directory." & _
                          @CR & "Please put file in same directory as script!" )
        EndIf
        
    Case Else
        ;Do nothing here
    EndSelect
WEnd
Link to comment
Share on other sites

Nice, im trying to make a preview option now, and a way to browse through the default windows wallpapers.

Anyone find any problems with this yet?

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

  • Moderators

Nice, im trying to make a preview option now, and a way to browse through the default windows wallpapers.

Anyone find any problems with this yet?

It's nice work Don... I played with it a bit... took out some of the $file_path(s) because the 2nd GUI I made pretty much took care of that and made sure that it only searched for .bmp files.... Mine addition(s) could still use "alot" of work :D... :
#include <GUIConstants.au3>

;Constants used in the Dll call

Dim Const $SPI_SETDESKWALLPAPER = 20;
Dim Const $SPIF_UPDATEINIFILE = 0x01;
Dim Const $SPIF_SENDWININICHANGE = 0x02;
Dim Const $REGISTRY_PATH = "HKEY_CURRENT_USER\Control Panel\Desktop"
Dim $file_name = '', $change = 1111111111, $file_path = '', $DoneLabel = 1111111111

;create the gui
$wall_change = GUICreate( "Don's Wallpaper Changer",300, 300 )

;create a simple about message for the script
GUICtrlCreateGroup( "What this does...", 15, 15, 270, 55 )
GUICtrlCreateLabel( "This program allows you to easily change the picture and style of your wallpaper.", 20, 30, 260, 30 )
GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group

; now that the GUI is created, show the gui and await user interaction
GUISetState(@SW_SHOW)

GUICtrlCreateGroup( "Image ( must be *.bmp ): ", 15, 75, 270, 50 )
$file_button = GUICtrlCreateButton('Choose Folder', 20, 95, 260, 20)
GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group

GUICtrlCreateGroup( "Wallpaper Options: ", 15, 135, 270, 110 )
$tile = GUICtrlCreateRadio( "Tile", 30, 155, 240, 20 )
$center = GUICtrlCreateRadio( "Center", 30, 185, 240, 20 )
$stretch = GUICtrlCreateRadio( "Stretch", 30, 215, 240, 20 )
GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group


;set the default to center
GUICtrlSetState ($center, $GUI_CHECKED)

While 1
    $msg = GuiGetMsg()
    
    Select
    
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    
    Case $msg = $file_button
        $file_folder = FileSelectFolder('Choose a folder to browse:', @HomeDrive)
        If Not @error Then
            $file_name = _BrowseFolder($file_folder)
            If IsArray($file_name) Then
                If $DoneLabel <> 1111111111 Then GUICtrlDelete($DoneLabel)
                $file_path = $file_name[1] & $file_name[2]
                $change = GUICtrlCreateButton( "Change Wallpaper to " & $file_name[2] & '?', 20, 255, 260, 30 )
            Else
                $file_path = ''
            EndIf
        EndIf
    Case $msg = $change
        GUICtrlDelete($change)
        $change = 1111111111
        ;now that the file name is valid, try to locate the file in the script directory
        If $file_path <> '' Then
                ;now that we knwo the file exists, start making changes
                ;first update the wallpaper style in the registry
                
                ;used to check for DllCall and RegWrite errors
                Local $err
                
                ;Set tiled
                If BitAND(GUICtrlRead($tile), $GUI_CHECKED) = $GUI_CHECKED Then
                    $err = RegWrite( $REGISTRY_PATH, "WallpaperStyle", "REG_SZ", "1" )
                    $err += RegWrite( $REGISTRY_PATH, "TileWallpaper", "REG_SZ", "1" )
                ;Set centered
                ElseIf BitAND(GUICtrlRead($center), $GUI_CHECKED) = $GUI_CHECKED Then
                    $err = RegWrite( $REGISTRY_PATH, "WallpaperStyle", "REG_SZ", "1" )
                    $err += RegWrite( $REGISTRY_PATH, "TileWallpaper", "REG_SZ", "0" )                    
                ;Set stretched
                Else
                    $err = RegWrite( $REGISTRY_PATH, "WallpaperStyle", "REG_SZ", "2" )
                    $err += RegWrite( $REGISTRY_PATH, "TileWallpaper", "REG_SZ", "0" )                
                EndIf
            
                ;Now that the registry edits were attempted, check for any errors
                If $err <> 2 Then
                    MsgBox( 4096, "Registery Error!!!", "There was an error writing to the registry." )
                Else
                    ;No error writing to the registry, make the Dll call to change the image!
                    $err = DllCall( "User32.dll", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, _
                                    "int", 0, "string", $file_path, "int", $SPIF_UPDATEINIFILE )
                    If @error <> 0 Then
                        MsgBox( 4096, "Dll Error!!!", "There was an error making the Dll call." & @CR & "Error Code: " & @error )
                    EndIf 
                    $err = DllCall( "User32.dll", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, _
                                    "int", 0, "string", $file_path, "int", $SPIF_SENDWININICHANGE )
                    If @error <> 0 Then
                        MsgBox( 4096, "Dll Error!!!", "There was an error making the Dll call." & @CR & "Error Code: " & @error )
                    EndIf                      
                EndIf
            $DoneLabel = GUICtrlCreateLabel('Your WallPaper was set to: ' & @CRLF & $file_name[2], 20, 255, 260, 40, 0X01)
            GUICtrlSetFont($DoneLabel, 9, 400, -1, 'Arial Bold')
            GUICtrlSetColor($DoneLabel, 0x0000FF)
        Else
            MsgBox( 4096, "Error!!!", "The file was not found in the current directory." & _
                          @CR & "Please put file in same directory as script!" )
        EndIf
    EndSelect
WEnd

Func _BrowseFolder($FolderToSearch)
    Local $SearchFolder = FileFindFirstFile($FolderToSearch & '\*.bmp')
    Local $bmpFile = FileFindNextFile($SearchFolder)
    If @error Then Return 0
    
    Local $BrowseGUI = GUICreate('WallPaper', 170, 225)
    Local $BrowseLabel = GUICtrlCreateLabel($bmpFile, 10, 10, 160, 20, 0x01)
    Local $BrowsePic = GUICtrlCreatePic($FolderToSearch & '\' & $bmpFile, 10, 35, 150, 150)
    Local $BrowseNext = GUICtrlCreateButton('Next', 5, 190, 50, 30)
    Local $BrowseSelect = GUICtrlCreateButton('Select', 60, 190, 50, 30)
    Local $BrowseCancel = GUICtrlCreateButton('Cancel', 115, 190, 50, 30)
    GUICtrlSetFont($BrowseLabel, 9, 400, -1, 'ARIAL BOLD')
    GUICtrlSetColor($BrowseLabel, 0XFF0000)
    GUISetState()
    While 1
        $BrowseMsg = GUIGetMsg()
        Select
            Case $BrowseMsg = -3 Or $BrowseMsg = $BrowseCancel
                ExitLoop
            Case $BrowseMsg = $BrowseNext
                $bmpFile = FileFindNextFile($SearchFolder)
                If @error Then 
                    GUICtrlSetState($BrowseNext, $GUI_DISABLE)
                Else
                    GUICtrlSetImage($BrowsePic, $FolderToSearch & '\' & $bmpFile)
                    GUICtrlSetData($BrowseLabel, $bmpFile)
                EndIf
            Case $BrowseMsg = $BrowseSelect
                GUIDelete($bmpFile)
                Return StringSplit($FolderToSearch & '\' & Chr(01) & $bmpFile, Chr(01))
        EndSelect
    WEnd
    GUIDelete($bmpFile)
    Return 0
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

nice browser, ill look at that more when i get home, im workin on adding a preview feature where you can either preview the bmp in a gui or preview the actual wallpaper option.

thanks for you add-on/input smoke_n and slightly_abnormal :D

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

  • 1 month later...

I need some help... I took the code and changed it a bit so that I could get an image of our local doppler radar. It will not place it on the desktop though.

Any ideas?

Dim Const $SPI_SETDESKWALLPAPER = 20
Dim Const $SPIF_UPDATEINIFILE = 0x01
Dim Const $SPIF_SENDWININICHANGE = 0x02
Dim Const $REGISTRY_PATH = "HKEY_CURRENT_USER\Control Panel\Desktop"
Dim Const $Radar = 'http://home1.wane.com/Weather/radar_now.jpg'
Dim Const $file_path = 'C:\radarnow.jpg'
Dim Const $New_File_path = 'C:\radarnow.bmp'


While 1
    _SetImage()
    Sleep(1000*60*2)
WEnd

Func _SetImage()
    $i = InetGet ($Radar,$file_path,1,0)
    FileDelete($New_File_path)
    FileCopy($file_path,$New_File_path)
    FileDelete($file_path)
    If FileExists($New_File_path) Then
        RegWrite( $REGISTRY_PATH, "WallpaperStyle", "REG_SZ", "2" )   
        RegWrite( $REGISTRY_PATH, "TileWallpaper", "REG_SZ", "0" )
        DllCall( "User32.dll", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, "int", 0, "string",$New_File_path, "int", $SPIF_UPDATEINIFILE )
        DllCall( "User32.dll", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, "int", 0, "string",$New_File_path, "int", $SPIF_SENDWININICHANGE )
    EndIf
EndFunc
INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...
Link to comment
Share on other sites

Are there any error codes/msgs or does it jsut run successfully but not display on the desktop. I think the problem might be in this area:

FileDelete($New_File_path)
    FileCopy($file_path,$New_File_path)
    FileDelete($file_path)

I think you might have to open the file with some program then save it as a .bmp in order for it to be recognized and displayed as a .bmp.

Let me know if opening and resaving works or what kind of error messages you are getting.

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

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...