Jump to content

Another Wallpaper Switcher


smstroble
 Share

Recommended Posts

I know there are a lot of them out there but i like mine better :idiot:

Features:

Full GUI

PVW32Con.exe is used for converting many many image formats to BMP ( if you dont trust the one i packaged have a look at http://www.pictview.com/pvw.htm my prog uses the command line version)

Auto switch between a select list of wallpapers

Remembers all lists

Minimizes to Tray

Umm some other stuff i forgot, havent worked on this project in a while, dident think i was going to release it.

 _linenums:0'>#cs
-------------------------------------------
|||||||||||||||||||||||||||||||||||||||||||
-------------------------------------------
Version Info
--------------
Complete Wallpaper Switcher V3.2

Changes:
I dont remember anymore...
-------------------------------------------
|||||||||||||||||||||||||||||||||||||||||||
-------------------------------------------
#ce


#include <Constants.au3>
#include <GUIConstants.au3>
#include <Array.au3>
#include <guilist.au3>
#include <File.au3>
AutoItSetOption("TrayAutoPause", 0)
AutoItSetOption("TrayMenuMode", 1)
AutoItSetOption("trayiconhide", 1)
; init variables
Dim $paperArray[1]
Dim $names[1]
Dim $tobedel[1]
Dim $autopaperarray[1]
Dim $pipesplit[1]
Dim $filedesktop[10]
$filedesktop[0] = 0
$d = 0
$previewpaper = ""
$oldlist = 0
$mainlistsel = 0
$c = 1
$new = 0
$main = 0
$num = 0
$chklist = -2
$b = 0
$i = 0
$list = ""
$timeractivate = 0
$gobuttonstatus = 0
$paperlist = 0
$listl = 0
$radio3 = 0
$timeinput = 0
$start = 0
$timetillswitch = 0
$preview = 0
$minipreview = 0
$fileexit = 0
$delete = 0
$Buttonadd = 0
$list1 = 0
$list2 = 0
$Buttonremove = 0
$setpaper = 0
$radio1 = 0
$radio2 = 0
$gobutton = 0
$fileopen = 0
$paperlist = 0
$selectdir = @MyDocumentsDir

startpaperprog()
;end init

func startpaperprog()
    $previewpaper = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper") ;set Preview paper to current wallpaper


    ;GUI
    
    Global $main = GUICreate("Wallpaper Switcher", 665, 471, 190, 219)
    
    Global $filemenu = GUICtrlCreateMenu("File")
    Global $fileopen = GUICtrlCreateMenuitem("Open", $filemenu)
    $filedesktop[0] = GUICtrlCreateMenu("Desktop", $filemenu)
    Global $fileexit = GUICtrlCreateMenuitem("Exit", $filemenu)
    Global $helpmenu = GUICtrlCreateMenu("Help")
    Global $helphelp = GUICtrlCreateMenuitem("Help", $helpmenu)
    GUICtrlSetState(-1,$GUI_DISABLE)
    Global $helpabout = GUICtrlCreateMenuitem("About", $helpmenu)
    GUICtrlSetState(-1,$GUI_DISABLE)
    
    Global $timetillswitch = GUICtrlCreateProgress(0, 434, 665, 17)
    GUICtrlSetColor(-1, 0xB2B4BF)
    Global $Preview = GUICtrlCreatePic($previewpaper, 328, 31, 320, 256, BitOR($WS_GROUP,$WS_THICKFRAME));,$SS_CENTERIMAGE))
    Global $paperlist = GUICtrlCreateList("", 24, 31, 209, 292)
    GUICtrlCreateLabel("Wallpapers", 24, 15, 57, 17)
    Global $new = GUICtrlCreateButton("New", 240, 39, 75, 25, 0)
    Global $delete = GUICtrlCreateButton("Delete", 240, 71, 75, 25, 0)
    Global $setpaper = GUICtrlCreateButton("Set", 240, 103, 75, 25, 0)
    Global $Radio1 = GUICtrlCreateRadio("Tile", 336, 293, 41, 17)
    Global $Radio2 = GUICtrlCreateRadio("Center", 392, 293, 57, 17)
    Global $Radio3 = GUICtrlCreateRadio("Fit Screen", 464, 293, 73, 17)

    Global $minipreview = GUICtrlCreatePic($previewpaper, 24, 303, 160, 128, $WS_GROUP)
    Global $Buttonadd = GUICtrlCreateButton(">", 348, 346, 31, 25, 0)
    Global $Buttonremove = GUICtrlCreateButton("<", 348, 381, 31, 25, 0)
    Global $List1 = GUICtrlCreateList("", 199, 332, 137, 97)
    GUICtrlCreateLabel("Wallpapers", 199, 316, 57, 17)
    Global $List2 = GUICtrlCreateList("", 391, 332, 137, 97)
    GUICtrlCreateLabel("Selected wallpapers", 391, 316, 99, 17)
    GUICtrlCreateLabel("Change Wallpaper Every", 531, 350, 121, 21)
    Global $timeinput = GUICtrlCreateInput(1, 548, 370, 30, 21, $ES_NUMBER)
    GUICtrlCreateLabel("Minutes", 580, 373, 40, 41)
    Global $gobutton = GUICtrlCreateButton("start", 623, 370, 30, 21)
    ; End GUI

    
    $filelines = _FileCountLines(@scriptdir & "\filelist.ini")
    do ;load wallpapers from filelist.ini
        $i = $i + 1
        $fileline = FileReadLine(@scriptdir & "\filelist.ini", $i)
        If $fileline = "[Auto Paper]" Then
            Do
                $i = $i + 1
                $fileline = FileReadLine(@scriptdir & "\filelist.ini", $i)
                If $fileline <> "" Then
                    If @error Then
                        MsgBox(0, "Error", "Unable to load Ppevious wallpapers")
                    EndIf
                    $split = StringSplit($fileline, "\")
                    _ArrayAdd ($autopaperarray, $split[$split[0]])
                    $autopaperarray[0] = $autopaperarray[0] + 1
                    GUICtrlSetData($List2, $split[$split[0]])
                    $index = _GUICtrlListFindString($list1, $split[$split[0]])
                    _GUICtrlListDeleteItem($list1, $index)
                    $c = $c + 1
                    EndIf
            Until $filelines <= $i
        Else
            If $fileline <> "" Then
                _ArrayAdd($paperArray, $fileline)
                If @error Then
                    MsgBox(0, "Error", "Unable to load Ppevious wallpapers")
                EndIf
                $split = StringSplit($paperArray[$c], "\")
                _ArrayAdd ($names, $split[$split[0]])
                GUICtrlSetData($paperlist, $split[$split[0]])
                GUICtrlSetData($List1, $split[$split[0]])
                $c = $c + 1
            EndIf
        EndIf
    until $filelines <= $i
    
    If    _GUICtrlListCount($list1) = 0 Then
        GUICtrlSetState($Buttonadd, $GUI_DISABLE)
    ElseIf _GUICtrlListCount($list2) = 0 Then
        GUICtrlSetState($Buttonremove, $GUI_DISABLE)
    EndIf
    eventhandler()
EndFunc

Func eventhandler()
    AutoItSetOption("trayiconhide", 1)
    HotKeySet("^!{f3}")
    GUISetState(@SW_SHOW)
    $oldlist = GUICtrlRead($paperlist)
    $minioldlist = GUICtrlRead($list1)
    GUICtrlSetState($radio3, $GUI_CHECKED)

    While 1 ;GUI related functions
        if $timeractivate Then
            $delay = GUICtrlRead($timeinput)
            $delay = $delay * 60000
            $current = TimerDiff($start)
            if $current >= $delay Then
                $newpaper = Random(1, $autopaperarray[0], 1)
                $b = _ArraySearch($names, $autopaperarray[$newpaper])
                applyimage($paperArray[$b], 2, 0)
                $start = TimerInit()
            EndIf
            $percent = $current / $delay
            $percent = $percent * 100
            GUICtrlSetData($timetillswitch, $percent)
        Endif

        
        
        $mainlistsel = GUICtrlRead($paperlist)
        if $mainlistsel <> $oldlist Then ;update priewview paper
            $b = _ArraySearch($names, $mainlistsel)
            GUICtrlSetImage($preview, $paperArray[$b])
            $oldlist = $mainlistsel
        EndIf
        
        $autolistsel = GUICtrlRead($list1)
        if $autolistsel <> $minioldlist Then ;update priewview paper for list1
            $b = _ArraySearch($names, $autolistsel)
            GUICtrlSetImage($minipreview, $paperArray[$b])
            $minioldlist = $autolistsel
        EndIf
        
        $msg = GuiGetMsg() ; get GUI event
        
        Select ;event handler
            Case $msg = $GUI_EVENT_MINIMIZE
                GUISetState(@SW_HIDE)
                AutoItSetOption("trayiconhide", 0)
                If $timeractivate = 1 Then
                    timeronly($delay)
                Else
                    HotKeySet("^!{f3}", "eventhandler")
                    While 1
                        $traymsg = TrayGetMsg()
                        Select
                            Case $traymsg = $TRAY_EVENT_PRIMARYDOUBLE
                                eventhandler()
                            EndSelect
                    WEnd
                EndIf
                
            Case $msg = $GUI_EVENT_CLOSE;GUI close
                if $timeractivate = 1 Then
                    GUISetState(@SW_HIDE)
                    timeronly($delay)
                Else
                    _FileWriteFromArray(@scriptdir & "\filelist.ini", $paperArray, 1)
                    
                    $inifile = FileOpen(@scriptdir & "\filelist.ini", 1)
                    FileWrite($inifile,@CRLF & "[Auto Paper]" & @CRLF)
                    
                    $x = 1
                    While $autopaperarray[0] >= $x
                        $b = _ArraySearch($names, $autopaperarray[$x])
                        FileWrite($inifile, $paperArray[$b] & @CRLF)
                        $x = $x + 1
                    WEnd
                    FileClose($inifile)
                    Exit
                EndIf
            Case $msg = $fileexit
                _FileWriteFromArray(@scriptdir & "\filelist.ini", $paperArray, 1)
                    
                $inifile = FileOpen(@scriptdir & "\filelist.ini", 1)
                FileWrite($inifile,@CRLF & "[Auto Paper]" & @CRLF)
                    
                $x = 1
                While $autopaperarray[0] >= $x
                    $b = _ArraySearch($names, $autopaperarray[$x])
                    FileWrite($inifile, $paperArray[$b] & @CRLF)
                    $x = $x + 1
                WEnd
                FileClose($inifile)
                Exit
                
            Case $msg = $new ;new button pressed
                paperselect()
            Case $msg = $delete ;delete button pressed
                If $mainlistsel <> "" Then
                    $b = _ArraySearch($names, $mainlistsel)
                    _ArrayDelete($paperArray, $ B) ;remove deleted entry from paperarray, removes it from ini output
                    _ArrayDelete($names, $ B) ;remove delted entry from names, allows paperpreview to operate normally
                    $selected = _GUICtrlListSelectedIndex($paperlist)
                    _GUICtrlListDeleteItem($paperlist, $selected)
                    _GUICtrlListSelectIndex($paperlist, $selected)
                    
                    
                    $dellist1index = _GUICtrlListSelectString($list1, $mainlistsel)
                    if $dellist1index <> $LB_ERR Then ;check if deleted item was in list
                        _GUICtrlListDeleteItem($list1, $dellist1index)
                        $countlist1 = _GUICtrlListCount($list1)
                        if $countlist1 = 0 Then ;check if deleted item was last in list, if true then disable add(>) button
                            GUICtrlSetState($Buttonadd, $GUI_DISABLE)
                        EndIf
                    EndIf
                    
                    
                    $dellist2index = _GUICtrlListSelectString($list2, $mainlistsel)
                    
                    $b = 0
                    $nothere = 0
                    While $mainlistsel <> $autopaperarray[$b] ;deturmine index number of removed string in paperarray and names
                        $b = $b + 1
                        if $b > $autopaperarray[0] Then
                            $nothere = 1
                            ExitLoop
                        EndIf
                    WEnd
                    if $nothere = 0 Then
                        _ArrayDelete($autopaperarray, $ B) 
                        $autopaperarray[0] = $autopaperarray[0] - 1
                    EndIf
                    
                    
                    if $dellist2index <> $LB_ERR Then ;check if deleted item was in list
                        _GUICtrlListDeleteItem($list2, $dellist2index)
                        $countlist2 = _GUICtrlListCount($list2)
                        if $countlist2 = 0 Then ;check if deleted item was last in list, if true then disable remove(<) button
                            GUICtrlSetState($Buttonremove, $GUI_DISABLE)
                        EndIf
                    EndIf
                EndIf
            Case $msg = $setpaper ;set button pressed
                $b = _ArraySearch($names, $mainlistsel)
                If GUICtrlread($radio1) = $GUI_CHECKED Then ;wallpaper option tile
                    $s_style = 1
                    $s_tile = 1
                    applyimage($paperArray[$b],$s_style,$s_tile)
                ElseIf GUICtrlread($radio2) = $GUI_CHECKED Then ;wallpaper option center
                    $s_style = 1
                    $s_tile = 0
                    applyimage($paperArray[$b],$s_style,$s_tile)
                ElseIf  GUICtrlread($radio3) = $GUI_CHECKED Then ;wallpaper option Stretch
                    $s_style = 2
                    $s_tile = 0
                    applyimage($paperArray[$b],$s_style,$s_tile)
                Else
                    MsgBox(0, "Error", "Please Select Display Style")
                EndIf
            Case $msg = $Buttonadd ; add(>) button pressed
                if GUICtrlRead($list1) Then ;if 0 endif
                    $list1slected = GUICtrlRead($list1)
                    $list1selindex = _GUICtrlListSelectedIndex($list1)
                    If $list1selindex = 0 Then
                        $previewpaper = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper")
                        GUICtrlSetImage($preview, $previewpaper)
                    EndIf
                    GUICtrlSetData($List2, $list1slected)
                    _ArrayAdd($autopaperarray, $list1slected)
                    $autopaperarray[0] = $autopaperarray[0] + 1
                    _GUICtrlListDeleteItem($list1, $list1selindex)
                    GUICtrlSetState($Buttonremove, $GUI_ENABLE)
                    $countlist1 = _GUICtrlListCount($list1)
                    if $countlist1 = 0 Then ;last entry in list?
                        GUICtrlSetState($Buttonadd, $GUI_DISABLE) ;yes diable add(>) button
                    Else
                        GUICtrlSetState($Buttonadd, $GUI_ENABLE) ;no enable add(>) button if not allready enabled
                    EndIf
                    _GUICtrlListSelectIndex($list1, $list1selindex)
                EndIf
            Case $msg = $Buttonremove ; remove(<) button pressed
                if GUICtrlRead($list2) Then ;if 0 returned endif
                    $list2slected = GUICtrlRead($list2)
                    $list2selindex = _GUICtrlListSelectedIndex($list2)
                    GUICtrlSetData($List1, $list2slected)
                    $autodelindex = _ArraySearch($autopaperarray, $list2slected)
                    _ArrayDelete($autopaperarray, $autodelindex)
                    $autopaperarray[0] = $autopaperarray[0] - 1
                    _GUICtrlListDeleteItem($list2, $list2selindex)
                    $countlist2 = _GUICtrlListCount($list2)
                    if $countlist2 = 0 Then ;last entry in list?
                        GUICtrlSetState($Buttonremove, $GUI_DISABLE) ;yes diable remove(<) button
                    Else
                        GUICtrlSetState($Buttonadd, $GUI_ENABLE) ;no enable remove(<) button if not allready enabled
                    EndIf
                    _GUICtrlListSelectIndex($list2, $list2selindex)
                EndIf
            Case $msg = $gobutton ;Go button pressed
                $time = GUICtrlRead($timeinput)
                If $gobuttonstatus = 0 Then
                    if $time <> "" Then
                        $listcount = _GUICtrlListCount($list2)
                        if $listcount <> 0 Then
                            $timeractivate = 1
                            Global $start = TimerInit()
                            GUICtrlSetData($gobutton, "stop")
                            $gobuttonstatus = 1
                        EndIf
                    EndIf
                Else
                    $timeractivate = 0
                    $gobuttonstatus = 0
                    GUICtrlSetData($gobutton, "start")
                EndIf
            Case $msg = $fileopen
                paperselect()
        EndSelect
    WEnd
    Exit
EndFunc

Func timeronly($delay)
    AutoItSetOption("trayiconhide", 0)
    HotKeySet("^!{f3}", "eventhandler")
    While 1
        $traymsg = TrayGetMsg()
        Select
            Case $traymsg = $TRAY_EVENT_PRIMARYDOUBLE
                eventhandler()
        EndSelect
        $delay = GUICtrlRead($timeinput)
        $delay = $delay * 60000
        $current = TimerDiff($start)
        if $current >= $delay Then
            $newpaper = Random(1, $autopaperarray[0], 1)
            $b = _ArraySearch($names, $autopaperarray[$newpaper])
            applyimage($paperArray[$b], 2, 0)
            $start = TimerInit()
        EndIf
        $percent = $current / $delay
        $percent = $percent * 100
        GUICtrlSetData($timetillswitch, $percent)
    WEnd
EndFunc

Func paperselect() ;select new wallpaer and add to wallpapaer list in GUI
    $fileopened = FileOpenDialog("Select Wallpaper", $selectdir, "Images (*.jpg;*.jpeg;*.bmp;*.png;*.pic;*.img;*.gif)", 5)
    If @error Then
        Return(0)
    EndIf
    $selectdir = @WorkingDir
    $pipesplit = StringSplit($fileopened, "|")
    if $pipesplit[0] = 1 Then
        ;MsgBox(0, "chk", "position1")
        _ArrayAdd($paperArray, $pipesplit[1])
        $split = StringSplit($fileopened, "\")
        _ArrayAdd($names, $split[$split[0]])
        GUICtrlSetData($paperlist, $split[$split[0]])
        GUICtrlSetData($List1, $split[$split[0]])
    Else
        $runs = 2
        ;MsgBox(0, "chk", "position2")
        While $pipesplit[0] <> $runs
            ;MsgBox(0, "chk", "position3")
            _ArrayAdd($paperArray, $pipesplit[1] & "\" &$pipesplit[$runs])
            _ArrayAdd($names, $pipesplit[$runs])
            GUICtrlSetData($paperlist, $pipesplit[$runs])
            GUICtrlSetData($List1, $pipesplit[$runs])
            $runs = $runs + 1
        WEnd
    EndIf
    GUICtrlSetState($Buttonadd, $GUI_ENABLE)
    $c = 1 + $c
    _FileWriteFromArray(@scriptdir & "\filelist.ini", $paperArray, 1)
    Return(0)
EndFunc

Func applyimage($s_path, $s_style, $s_tile) ;Apply wallpaper to windows desktop
    ;read last 4 characters of file name
    $apply_type = StringRight($s_path, 4)
    ;if not .bmp use pvw32con to convert to .bmp and copy to windowsdir\xwall.bmp
    If $apply_type = ".jpg" Or _
            $apply_type = "jpeg" Or _
            $apply_type = ".gif" Or _
            $apply_type = ".png" Or _
            $apply_type = ".pic" Or _
            $apply_type = ".png" Then
        FileDelete(@ScriptDir & "\xwall.bmp")
        RunWait(@ScriptDir & "\pvw32con.exe " & '"' & $s_path & '"' & " -w --oo " & '"' & @ScriptDir & "\xwall.bmp" & '"', _
                @ScriptDir, @SW_HIDE)
    Else
        ;if .bmp copy to windowsdir\xwall.bmp
        FileCopy($s_path, @scriptdir & "\xwall.bmp", 1)
    EndIf
    ;change wallpaper settings in registry
    RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", $s_style)
    RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallpaper", "REG_SZ", $s_tile)
    Sleep(250)
    ;apply now wallpaper and refresh windows wallpaper
    DllCall("User32.dll", "int", "SystemParametersInfo", "int", 20, "int", 0, "string", @ScriptDir & "\xwall.bmp", "int", 0x01)
    Return(0)
EndFunc

Let me know what ya think, and what i inevetably messed up...

Cedit to xcal for making the function that converts the image via picview and updates the desktop. Original Post

Edit: Minor fix's, fixed all the AU3Check warnings, removed the desktop menu that dosent do anything.

Edit2: Allmost forgot the icon I use for it :-)

Edited by smstroble

MUHAHAHAHAHA

Link to comment
Share on other sites

This looks very good. Here are a few problems and 1 request.

I found this error (still runs fine though).

CODE
>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\me\Desktop\Wallpaper Switch.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

+> Starting AutoIt3Wrapper v.1.7.4

>Running AU3Check (1.54.6.0) params: from:C:\Program Files\AutoIt3

C:\Documents and Settings\me\Desktop\Wallpaper Switch.au3(164,35) : WARNING: $list1: possibly used before declaration.

$minioldlist = GUICtrlRead($list1)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\me\Desktop\Wallpaper Switch.au3(104,58) : WARNING: $list1: declared global in function only. Prefer top of file.

Global $List1 = GUICtrlCreateList("", 199, 332, 137, 97)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\me\Desktop\Wallpaper Switch.au3 - 0 error(s), 2 warning(s)

->AU3Check ended.rc:1

>Running:(3.2.2.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\me\Desktop\Wallpaper Switch.au3"

I am running WinXP so the progress bar is pushing the small picture in lower left up into the area of the ListView.

I run dual moniters @ both home and work so this would be very nice if it could support that. I currently use UltraMon to handle dual screen wallpapers.

Kohr

Edited by Kohr
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...