Sign in to follow this  
Followers 0
user52

Simple Wallpaper Switcher

2 posts in this topic

this may help beginners as i tried to keep it simple

uses PVW32Con.exe to convert image formats bitmap (*.bmp)

to use

1. save PVW32Con.exe to C:\

2. copy/open script using SciTE, run script by going to Tools> Go (or simply F5)

3. double click picture to set as wallpaper

more about the dllcall used to change the wallpaper SystemParametersInfo

#region
#include <GuiTreeView.au3>
#include <GUIConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiCombo.au3>

HotKeySet("{ESC}", "_Exit")

Global $path = @MyDocumentsDir

$DebugIt_KBdbg = 1
Global $Clicked = 0
Global Const $WM_NOTIFY = 0x004E
Const $NM_FIRST = 0
Const $NM_CLICK = -2
Const $NM_DBLCLK = -3

Global Const $WM_COMMAND = 0x0111

$gui = GUICreate("Wallpaper", 670, 560, 192, 125, $WS_SYSMENU, 0)
    GUISetFont(10, 400, 0, "MS Sans Serif")
$Done = GUICtrlCreateButton("Done", 520, 456, 97, 41, 0)
$input_directory = GUICtrlCreateInput($path, 8, 8, 345, 25)
$button_browse = GUICtrlCreateButton("Browse", 355, 8, 70)
$List1 = GUICtrlCreateList("", 8, 38, 417, 410, -1, 0)
$Up = GUICtrlCreateButton("Up", 8, 456, 49, 41, 0)
$Down = GUICtrlCreateButton("Down", 64, 456, 49, 41, 0)
$Preview = GUICtrlCreateGroup("Preview", 432, 8, 227, 207)
$Preview_pic = GUICtrlCreatePic("C:\wallpaper.bmp", 440, 27, 210, 180)
$Combo1 = GUICtrlCreateCombo("Center", 472, 222, 145, 24, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Stretch|Tile")
$button_default = GUICtrlCreateButton("", -100,-100,0,0)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

Local $a_PartsRightEdge[2] = [600, -1]
Local $a_PartsText[2] = ["", ""]
$StatusBar1 = _GUICtrlStatusBarCreate($gui, $a_PartsRightEdge, $a_PartsText)

SearchDir()

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)
#endregion

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $button_browse
        $sTmpFile = FileSelectFolder("Select Folder:", "", 4, @MyDocumentsDir)
        If Not @error Then
            GUICtrlSetData($input_directory, $sTmpFile)
            SearchDir()
        EndIf
    Case $msg = $Done
        Exit
    Case $msg = $button_default
        List_DoubleClick()
    Case $msg = $Combo1
        ChangeWallpaper(GetCurrentlySelected())
    EndSelect
WEnd
Exit

Func ChangeWallpaper($path_of_wallpaper)
    If Not FileExists($path_of_wallpaper) Then
        Return -1
    EndIf
    
    $pos_slash = StringInStr($path_of_wallpaper, "\", 1, -1)
    $filename = StringTrimLeft($path_of_wallpaper, $pos_slash)
    $pos_dot = StringInStr($filename, ".", 1, -1)
    $filename_noext = StringTrimRight($filename, StringLen($filename) - $pos_dot + 1)
    dbg($pos_dot)
    dbg($path_of_wallpaper)
    dbg($pos_slash)
    dbg($filename)
    dbg($filename_noext)
    
    ;if jpg then covert jpg to bmp
        ShellExecuteWait("C:\PVW32Con.exe", """" & $path_of_wallpaper & """" & " -w --o C:\wallpaper.bmp", "", "", @SW_HIDE)
        
    ;write new file location to reg using type specified
    $sel = _GUICtrlComboGetCurSel($Combo1)
    If $sel = 0 Then ;center
        ;TileWallpaper=0
        ;WallpaperStyle=0
        RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallpaper", "REG_SZ", 0)
        RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", 0)
    ElseIf $sel = 1 Then ;stretch
        ;TileWallpaper=0
        ;WallpaperStyle=2
        RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallpaper", "REG_SZ", 0)
        RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", 2)
    ElseIf $sel = 2 Then ;tile
        ;TileWallpaper=1
        ;WallpaperStyle=0
        RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallpaper", "REG_SZ", 1)
        RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", 0)
    EndIf
        
    ;call dll using file location
        $SPI_SETDESKWALLPAPER = 20
        $SPIF_UPDATEINIFILE = 1
        $SPIF_SENDCHANGE = 2
        DLLCall("user32.dll", _
                "int", "SystemParametersInfo", _
                "int", $SPI_SETDESKWALLPAPER, _
                "int", 0, _
                "str", "C:\wallpaper.bmp", _
                "int", BitOR($SPIF_UPDATEINIFILE,$SPIF_SENDCHANGE) )
EndFunc
Func _Exit()
    Exit
EndFunc
Func dbg($a)
    ConsoleWrite($a & @LF)
EndFunc
Func GetCurrentlySelected()
    $sel = GUICtrlRead($List1)
    $image_path = $path & $sel
    If Not FileExists($image_path) Then
        Return -1
    Else
        dbg("selected: " & $image_path)
        Return $image_path
    EndIf
EndFunc
Func UpdateStatusBar()
    _GUICtrlStatusBarSetText($StatusBar1, GetCurrentlySelected(), 0)
EndFunc
Func SetCurrentlySelected()
    GUICtrlSetImage($Preview_pic, GetCurrentlySelected())
EndFunc
Func SearchDir($dir="")
    ;clear List
        GUICtrlSetData($List1, "")
        
    ;check for blank dir
        If $dir = "" Then
            $dir = GUICtrlRead($input_directory)
        Else
            Return
        EndIf
    ;check for trailing slash
        $a = StringTrimLeft($dir, StringLen($dir) - 1)
        dbg($a)
        If $a <> "\" Then
            $dir = $dir & "\"
        EndIf
    ;check dir exists
        If Not FileExists($dir) Then
            Return -1
        EndIf
    ;update global path
        $path = $dir
    ;search
        ;search for database directory
            Local $search = FileFindFirstFile($dir & "*.*")
        ;not found
            If $search = -1 Then
                MsgBox(0, "", "nothing found in: " & $dir & "*.*")
                Return 0
            EndIf
        ;found
            While 1
                $found = FileFindNextFile($search) 
                If @error Then
                    ExitLoop
                Else
                    $a = FileGetAttrib($dir & $found)
                    
                    ;folder found
                        If StringInStr($a, "D", 1) <> 0 Then
                            ;
                        Else
                            GUICtrlSetData($List1, $found)
                        EndIf
                EndIf
            WEnd
    ;close search
        FileClose($search)
EndFunc
Func List_Click()
    SetCurrentlySelected()
    UpdateStatusBar()
EndFunc
Func List_DoubleClick()
    ChangeWallpaper(GetCurrentlySelected())
EndFunc
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam
    Local Const $LBN_ERRSPACE = (-2);
    Local Const $LBN_SELCHANGE = 1;
    Local Const $LBN_DBLCLK = 2;
    Switch $nID
        Case $List1
            Switch $nNotifyCode
                Case $LBN_SELCHANGE
                    List_Click()
                Case $LBN_DBLCLK
                    List_DoubleClick()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites



post-14453-1177649674_thumb.jpg

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