Jump to content
Sign in to follow this  
tylerh27

Change Desktop Walpaper?

Recommended Posts

tylerh27

How can i do this? say i have a jpg image on my desktop, and i want to like:

ChangeBackground("image.jpg")

something like that?

Share this post


Link to post
Share on other sites
Melba23

tylerh27,

Have you searched the forum? :huh:

There are lots of threads out there when I looked for "+change +wallpaper". ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Danyfirex

Share this post


Link to post
Share on other sites
NDog

Its quite ironic, I googled for +change +wallpaper +autoit and I ended up here!

I would like to see if anyone has a good working desktop wallpaper script for autoit that works in XP and 7, has jpg support and supports different strech modes.

Will keep googling!

Share this post


Link to post
Share on other sites
guinness

What did you try? I would also recommend you not to post in every thread that you find about there being a poor or no example. I found code once in the forum so it shouldn't be that difficult.

Edited by guinness
  • Like 1

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Tripredacus

Its quite ironic, I googled for +change +wallpaper +autoit and I ended up here!

Google supports very little boolean, and doesn't see the + as an operator, but as a character. This is confusing since it does support using - as an operator.

Share this post


Link to post
Share on other sites
BrewManNH

Google uses the "+" as a way to tell it that it must include that word in the search rather than it would be nice to have it in the results.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Tripredacus

Google uses the "+" as a way to tell it that it must include that word in the search rather than it would be nice to have it in the results.

I've found that using the "+" doesn't usually work. I know what you mean tho... I usually have to resort to putting the term in quotes to get that exact match.

Share this post


Link to post
Share on other sites
Chimaera

There is several examples but a universal one fit all version for XP - 8 isnt so simple from my browsings

This was Smoke N's version which works on XP but cant handle jpg/png etc

#include

;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

But i use this bit on vista and above

; Changes the wallpaper to $sFilename using $iType as:
; 1 Tiled
; 2 Centered
; 3 Stretched
; any other value (usually 0) unchanged
;
; Returns
; 0 if everything is allright.
; -1 if $sFile does not exist. @error is set to 1
; -2 if £sFile is not a .bmp file. @error is set to 2
Func _ChangeWallpaper($sFile, $iType)
If Not FileExists($sFile) Then
SetError(1)
Return -1
EndIf
If StringTrimLeft($sFile, StringInStr($sFile, '.', 0, -1)) <> 'jpg' Then
SetError(2)
Return -2
EndIf

Select
Case $iType = 1
RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '1')
RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0')
Case $iType = 2
RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0')
RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0')
Case $iType = 3
RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0')
RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '2')
Case Else

EndSelect

RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
DllCall("User32.dll", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $sFile, "int", 0)
Return 0
EndFunc ;==>_ChangeWallpaper

And i call it like this

Case @DesktopWidth = 1920 And @DesktopHeight = 1080; 1920x1080
FileCopy(@WorkingDir & "\TS_1920x1080.jpg", $dest_dir & "\TS_1920x1080.jpg", 9)
Sleep (1000)
_ChangeWallpaper($dest_dir & "\TS_1920x1080.jpg", 2)

Dunno if it helps but there are other bits and pieces around the forum

Its a shame there isnt a universal one that uses any file type... maybe one day

Share this post


Link to post
Share on other sites
NDog

Works in XP, supports jpg, using the GDI functions to convert jpg to bmp. Works in windows 7 as well, but I think it is redundant to use GDI functions to do that.

#Include <GDIPlus.au3>
If $CmdLine[0] = 1 And $CmdLine[1] = "/?" Then
 _ShowUsage()
EndIf
If $CmdLine[0] <> 2 Then
 _ShowUsage()
EndIf
If $CmdLine[0] = 2 Then
 $file = $CmdLine[1]
 $type = $CmdLine[2]
 _ChangeWallpaper($file, $type)
EndIf

Func _ChangeWallpaper($sFile, $iType)
 ; Changes the wallpaper to $sFilename using $iType as:
 ; 1 Tiled
 ; 2 Centered
 ; 3 Stretched
 ; any other value (usually 0) unchanged
 ;
 ; Returns
 ; 0 if everything is allright.
 ; -1 if $sFile does not exist. @error is set to 1
 ; -2 if $sFile is not bmp or jpg file. @error is set to 2
 
 If Not FileExists($sFile) Then
  SetError(1)
  Return -1
 EndIf
 $apos = StringInStr($sFile, "\", 0, -1)
 $bpos = StringInStr($sFile, ".", 0, -1)
 
 $sFileName = StringMid($sFile,$apos + 1 ,$bpos - $apos - 1)
 ConsoleWrite($sFileName & @CRLF)
 If Not StringRight($sFile,3) = "jpg" Or Not StringRight($sFile,3) = "bmp" Then
  SetError(2)
  Return -2
 EndIf
 Select
 Case $iType = 1
  RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '1')
  RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0')
 Case $iType = 2
  RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0')
  RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0')
 Case $iType = 3
  RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0')
  RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '2')
 Case Else
  
 EndSelect
 ; Convert jpg to bmp
 If StringRight($sFile,3) = "jpg" Then
  _GDIPlus_Startup()
  $hImage = _GDIPlus_ImageLoadFromFile($sFile)
  $sCLSID = _GDIPlus_EncodersGetCLSID("BMP")
  _GDIPlus_ImageSaveToFileEx($hImage, @TempDir & "\"&$sFileName&".bmp", $sCLSID)
  _GDIPlus_Shutdown()
  $sFile = @TempDir & "\"&$sFileName&".bmp"
 EndIf
 Sleep(500)
 RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
 DllCall("user32", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $sFile, "int", 0)
EndFunc ;==>_ChangeWallpaper
Func _ShowUsage()
 Local $msg
 $msg = "ChangeWallpaper Copyright (c) " & @YEAR & "  ndog" & @CRLF & @CRLF
 $msg &= "Usage: ChangeWallpaper [ /? ] or [ filename type ]" & @CRLF & @CRLF
 $msg &= "filename must be .bmp or .jpg" & @CRLF & @CRLF
 $msg &= "type can be 1, 2 or 3" & @CRLF & @CRLF
 $msg &= "ChangeWallpaper /? shows this About Dialog" & @CRLF & @CRLF
 MsgBox(0x1040, "", $msg, 30)
 Exit
EndFunc ;==>_ShowUsage

Share this post


Link to post
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
Sign in to follow this  

×