Sign in to follow this  
Followers 0
dantay9

Change Desktop Wallpaper

6 posts in this topic

#1 ·  Posted (edited)

This has already been made, but I think this one is more universal and easier to understand.

Change Wallpaper.au3

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This has already been made, but I think this one is more universal.

Func 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 by dmob

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

update.

Func 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 by ghetek

Share this post


Link to post
Share on other sites

Oh. Thanks for fixing that ghetek. Simple mistake.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

Oh. Thanks for fixing that ghetek. Simple mistake.

i can't seem to get it work..

how do i get it work?

Share this post


Link to post
Share on other sites

i can't seem to get it work..

how do i get it work?

ouh i got it now...thanks

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  
Followers 0