Jump to content

Change Desktop Wallpaper


dantay9
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 1 month later...

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