Jump to content

Gui Buttons Don't Work


Pieter
 Share

Recommended Posts

Hello everyone, I am not very familiar with the AutoIt GUI functions, and I'm experiecing the following problem. The buttons of my GUI don't work, althought I defined an action through the GUICtrlSetOnEvent function. This is the complete code of my script (it's not finished yet, so don't pay attention to the rest of the code):

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Pieter De Decker
;
; Script Function:
;   Adds wallpapers to the Wallpaper directory of Wallpaper Manager
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiConstants.au3>
Break(0)
Opt("TrayIconHide", 1)
HotKeySet("!+d", "AddWP")
HotKeySet("!+x", "ExitWPD")
; Generate Add window
GuiCreate("AddWindow", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")

$PhotoDownloadURL = GuiCtrlCreateInput("http://", 10, 50, 350, 20)
$Introtext = GuiCtrlCreateLabel("Please enter the URL of the wallpaper that you want to add.", 10, 10, 340, 30)
$Btn_OK = GuiCtrlCreateButton("Add", 10, 90, 170, 30)
GUICtrlSetOnEvent( $Btn_OK, "Downloader")
    
$Btn_Cancel = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
GUICtrlSetOnEvent( $Btn_Cancel, "CancelAddWP")
While 1
; endless waiting loop
    Sleep(500)              ; some sleep to be sure not to overload the machine
WEnd
Func AddWP()
    GuiSetState( @SW_SHOW, "AddWP")
    While 1
        $msg = GuiGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc
Func Downloader()
    GUIDelete("AddWindow")
    Opt("TrayIconHide", 0)
    TrayTip( "Wallpaper Manager", "Downloading new wallpaper...", 5, 1)
; some work still needed here
; InetGet( GUICtrlRead($PhotoDownloadURL), @ScriptDir & "\Wallpapers", 0, 0)
; TrayTip( "Wallpaper Manager", "Download complete.", 5, 1)
EndFunc
Func CancelAddWP()
    GUISetState( @SW_HIDE, "AddWindow")
EndFunc
Func ExitWPD()
    Exit
EndFunc
What am I doing wrong?

Thanks in advance,

Pieter

iPod + Online calendars = iPodCALsync

Link to comment
Share on other sites

This appears to work. I commented directly on the code.

#include <GuiConstants.au3>
Break(0)
Opt("TrayIconHide", 1)
Opt ("GUIOnEventMode", 1); have to set oneventmode to 1 in order to use it...
HotKeySet("!+d", "AddWP")
HotKeySet("!+x", "ExitWPD")
; Generate Add window
$AddWin = GuiCreate("AddWindow", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")

$PhotoDownloadURL = GuiCtrlCreateInput("http://", 10, 50, 350, 20)
$Introtext = GuiCtrlCreateLabel("Please enter the URL of the wallpaper that you want to add.", 10, 10, 340, 30)
$Btn_OK = GuiCtrlCreateButton("Add", 10, 90, 170, 30)
GUICtrlSetOnEvent( $Btn_OK, "Downloader")
    
$Btn_Cancel = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
GUICtrlSetOnEvent( $Btn_Cancel, "CancelAddWP")
; GUISetState (); uncomment if you want GUI to be shown at the beginning
While 1
; endless waiting loop
    Sleep(500)             ; some sleep to be sure not to overload the machine
WEnd
Func AddWP()
    GuiSetState( @SW_SHOW, $AddWin); not needed if shown at the beginning
; guigetmsg() doesn't work with oneventmode, removed
EndFunc
Func Downloader()
   ; GUIDelete($AddWin); are you sure you want to delete it?  what if the user tries to show it again?  I suggest only hiding it
    GUISetState (@SW_HIDE, $AddWin)
    Opt("TrayIconHide", 0)
    TrayTip( "Wallpaper Manager", "Downloading new wallpaper...", 5, 1)
; some work still needed here
; InetGet( GUICtrlRead($PhotoDownloadURL), @ScriptDir & "\Wallpapers", 0, 0)
; TrayTip( "Wallpaper Manager", "Download complete.", 5, 1)
EndFunc
Func CancelAddWP()
    GUISetState( @SW_HIDE, $AddWin)
EndFunc
Func ExitWPD()
    Exit
EndFunc
Link to comment
Share on other sites

So it's only neccesary to do Opt("GUIOnEventMode", 1) before being able to create GUI events?

Anyway, thanks for the quick response and for the comments on the rest of the code. It all works fine now.

Edit: by the way, is it possible to change the users wallpaper by using AutoIt code?

Edited by Pieter

iPod + Online calendars = iPodCALsync

Link to comment
Share on other sites

The buttons stopped working again. Now they only work the first time I open the GUI.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Pieter De Decker
;
; Script Function:
;   Adds wallpapers to the Wallpaper directory of Wallpaper Manager
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiConstants.au3>
Break(0)
#NoTrayIcon
Opt("GUIOnEventMode", 1)
HotKeySet("!+d", "AddWP")
HotKeySet("!+x", "ExitWPD")
; Generate Add window
$GUI_ADD = GuiCreate("Add a new wallpaper", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
$PhotoDownloadURL = GuiCtrlCreateInput("http://", 10, 50, 350, 20)
$Introtext = GuiCtrlCreateLabel("Please enter the URL of the wallpaper that you want to add.", 10, 10, 340, 30)
$Btn_OK = GuiCtrlCreateButton("Download", 10, 90, 170, 30)
    GUICtrlSetOnEvent( $Btn_OK, "Downloader")
$Btn_Cancel = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
    GUICtrlSetOnEvent( $Btn_Cancel, "CancelAddWP")
GUISetState(@SW_HIDE, $GUI_ADD)

; Generate Filename window
$GUI_INSERT = GuiCreate("Insert filename", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
$FileName = GuiCtrlCreateInput("", 10, 50, 350, 20)
$Introtext2 = GuiCtrlCreateLabel("Please enter a filename.", 10, 10, 340, 30)
$Btn_OK2 = GuiCtrlCreateButton("Save", 10, 90, 170, 30)
    GUICtrlSetOnEvent($Btn_OK, "HideFilenameWindow")    
$Btn_Cancel2 = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
    GUICtrlSetOnEvent($Btn_Cancel, "CancelAddWP")

; Hide both windows
GUISetState(@SW_HIDE, $GUI_ADD)
GUISetState(@SW_HIDE, $GUI_INSERT)

IdleMode()

; Wait, that's all you have to do...
Func IdleMode()
    While 1
   ; endless waiting loop
        Sleep(500)             ; some sleep to be sure not to overload the machine
    WEnd
EndFunc

; Time for some action, user requested to add a new wallpaper
Func AddWP()
    GuiSetState( @SW_SHOW, $GUI_ADD)
    $clipbrdstring = ClipGet()
    If StringInStr($clipbrdstring, "http://") = 1 And (StringInStr($clipbrdstring, ".jpg") = 1 Or StringInStr($clipbrdstring, ".bmp") = 1 Or StringInStr($clipbrdstring, ".gif") = 1) Then
        GUICtrlSetData( $PhotoDownloadURL, $clipbrdstring)
    EndIf
EndFunc

; We're ready to start the download
Func Downloader()
    GUISetState( @SW_HIDE, $GUI_ADD)
    Opt("TrayIconHide", 0)
    $PhotoDownloadURL_Text = GUICtrlRead($PhotoDownloadURL)
    $PhotoFilenamePos = StringInStr($PhotoDownloadURL_Text, "/", 0, -1)
    $PhotoFilenamePos = $PhotoFileNamePos + 1
    $PhotoFilename = StringMid($PhotoDownloadURL_Text, $PhotoFilenamePos)
    GUICtrlSetData($FileName, $PhotoFilename)
    GUISetState( @SW_SHOW, $GUI_INSERT)
    TrayTip("Wallpaper Manager", "Downloading new wallpaper...", 5, 1)
    InetGet(GUICtrlRead($PhotoDownloadURL), @ScriptDir & "\Wallpapers\" & $PhotoFilename, 0, 0)
    TrayTip("Wallpaper Manager", "Download complete.", 5, 1)
    _ChangeWallpaper(@ScriptDir & "\Wallpapers\" & $PhotoFilename)
    Sleep(5000)
    Opt("TrayIconHide", 1)
    IdleMode()
EndFunc

; Run this after running the file name dialog thingy
Func HideFilenameWindow()
    GUISetState( @SW_HIDE, $GUI_INSERT)
EndFunc

; Run this when users cancels the add process
Func CancelAddWP()
    GUISetState(@SW_HIDE, $GUI_ADD)
    GUISetState(@SW_HIDE, $GUI_INSERT)
    IdleMode()
EndFunc

; Simple hotkey definition to quit
Func ExitWPD()
    Exit
EndFunc

Func _ChangeWallpaper($sFile, $iType = 2)
    Local Const $SPI_SETDESKWALLPAPER = 20
    Local Const $SPIF_SENDWININICHANGE = 0x2
; $iType: 1 = Tiled, 2 = Normal size, 3 = Stretched.
    If Not FileExists($sFile) Then Return 0
    If StringTrimLeft($sFile, StringInStr($sFile, '.', 0, -1)) <> 'bmp' Then Return 0
    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')
    EndSelect
    RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
    DllCall("user32", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, "int", 0, "str", $sFile, "int", $SPIF_SENDWININICHANGE)
    Return 1
EndFunc

iPod + Online calendars = iPodCALsync

Link to comment
Share on other sites

Update: the Download button from the first dialog is still not working.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Pieter De Decker
;
; Script Function:
;   Adds wallpapers to the Wallpaper directory of Wallpaper Manager
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiConstants.au3>
Break(0)
#NoTrayIcon
Opt("GUIOnEventMode", 1)
HotKeySet("!+d", "AddWP")
HotKeySet("!+x", "ExitWPD")
; Generate Add window
$GUI_ADD = GuiCreate("Add a new wallpaper", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
$PhotoDownloadURL = GuiCtrlCreateInput("http://", 10, 50, 350, 20)
$Introtext = GuiCtrlCreateLabel("Please enter the URL of the wallpaper that you want to add.", 10, 10, 340, 30)
$Btn_OK = GuiCtrlCreateButton("Download", 10, 90, 170, 30)
    GUICtrlSetOnEvent( $Btn_OK, "Downloader")
$Btn_Cancel = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
    GUICtrlSetOnEvent( $Btn_Cancel, "CancelAddWP")
GUISetState(@SW_HIDE, $GUI_ADD)

; Generate Filename window
$GUI_INSERT = GuiCreate("Insert filename", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
$FileName = GuiCtrlCreateInput("", 10, 50, 350, 20)
$Introtext2 = GuiCtrlCreateLabel("Please enter a filename.", 10, 10, 340, 30)
$Btn_OK2 = GuiCtrlCreateButton("Save", 10, 90, 170, 30)
    GUICtrlSetOnEvent($Btn_OK, "HideFilenameWindow")    
$Btn_Cancel2 = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
    GUICtrlSetOnEvent($Btn_Cancel, "CancelAddWP")

; Hide both windows
GUISetState(@SW_HIDE, $GUI_ADD)
GUISetState(@SW_HIDE, $GUI_INSERT)

IdleMode()

; Wait, that's all you have to do...
Func IdleMode()
    While 1
   ; endless waiting loop
        Sleep(500)             ; some sleep to be sure not to overload the machine
    WEnd
EndFunc

; Time for some action, user requested to add a new wallpaper
Func AddWP()
    GuiSetState( @SW_SHOW, $GUI_ADD)
    $clipbrdstring = ClipGet()
    If StringInStr($clipbrdstring, "http://") = 1 And (StringInStr($clipbrdstring, ".jpg") = 1 Or StringInStr($clipbrdstring, ".bmp") = 1 Or StringInStr($clipbrdstring, ".gif") = 1) Then
        GUICtrlSetData( $PhotoDownloadURL, $clipbrdstring)
    EndIf
EndFunc

; We're ready to start the download
Func Downloader()
    GUISetState( @SW_HIDE, $GUI_ADD)
    Opt("TrayIconHide", 0)
    $PhotoDownloadURL_Text = GUICtrlRead($PhotoDownloadURL)
    $PhotoFilenamePos = StringInStr($PhotoDownloadURL_Text, "/", 0, -1)
    $PhotoFilenamePos = $PhotoFileNamePos + 1
    $PhotoFilename = StringMid($PhotoDownloadURL_Text, $PhotoFilenamePos)
    GUICtrlSetData($FileName, $PhotoFilename)
    GUISetState( @SW_SHOW, $GUI_INSERT)
    TrayTip("Wallpaper Manager", "Downloading new wallpaper...", 5, 1)
    InetGet(GUICtrlRead($PhotoDownloadURL), @ScriptDir & "\Wallpapers\" & $PhotoFilename, 0, 0)
    TrayTip("Wallpaper Manager", "Download complete.", 5, 1)
    _ChangeWallpaper(@ScriptDir & "\Wallpapers\" & $PhotoFilename)
    Sleep(5000)
    Opt("TrayIconHide", 1)
    IdleMode()
EndFunc

; Run this after running the file name dialog thingy
Func HideFilenameWindow()
    GUISetState( @SW_HIDE, $GUI_INSERT)
EndFunc

; Run this when users cancels the add process
Func CancelAddWP()
    GUISetState(@SW_HIDE, $GUI_ADD)
    GUISetState(@SW_HIDE, $GUI_INSERT)
EndFunc

; Simple hotkey definition to quit
Func ExitWPD()
    Exit
EndFunc

; Wallpaper changer
Func _ChangeWallpaper($sFile, $iType = 2)
    Local Const $SPI_SETDESKWALLPAPER = 20
    Local Const $SPIF_SENDWININICHANGE = 0x2
; $iType: 1 = Tiled, 2 = Normal size, 3 = Stretched.
    If Not FileExists($sFile) Then Return 0
    If StringTrimLeft($sFile, StringInStr($sFile, '.', 0, -1)) <> 'bmp' Then Return 0
    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')
    EndSelect
    RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
    DllCall("user32", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, "int", 0, "str", $sFile, "int", $SPIF_SENDWININICHANGE)
    Return 1
EndFunc
I don't know what could be possibly wrong with my GUICtrlSetOnEvent statements.

iPod + Online calendars = iPodCALsync

Link to comment
Share on other sites

I tried to tell the program to wait until the Insert filename dialog gets closed, but now the Save and Cancel buttons don't work anymore. Where is the stupid mistake I made this time?

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Pieter De Decker
;
; Script Function:
;   Adds wallpapers to the Wallpaper directory of Wallpaper Manager
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiConstants.au3>
Break(0)
#NoTrayIcon
Opt("GUIOnEventMode", 1)
HotKeySet("!+d", "AddWP")
HotKeySet("!+x", "ExitWPD")
; Generate Add window
$GUI_ADD = GuiCreate("Add a new wallpaper", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
$PhotoDownloadURL = GuiCtrlCreateInput("http://", 10, 50, 350, 20)
$Introtext = GuiCtrlCreateLabel("Please enter the URL of the wallpaper that you want to add.", 10, 10, 340, 30)
$Btn_OK = GuiCtrlCreateButton("Download", 10, 90, 170, 30)
    GUICtrlSetOnEvent( $Btn_OK, "Downloader")
$Btn_Cancel = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
    GUICtrlSetOnEvent( $Btn_Cancel, "CancelAddWP")
GUISetState(@SW_HIDE, $GUI_ADD)

; Generate Filename window
$GUI_INSERT = GuiCreate("Insert filename", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
$FileName = GuiCtrlCreateInput("", 10, 50, 350, 20)
$Introtext2 = GuiCtrlCreateLabel("Please enter a filename.", 10, 10, 340, 30)
$Btn_OK2 = GuiCtrlCreateButton("Save", 10, 90, 170, 30)
    GUICtrlSetOnEvent($Btn_OK2, "HideFilenameWindow")   
$Btn_Cancel2 = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
    GUICtrlSetOnEvent($Btn_Cancel2, "CancelAddWP")

; Hide both windows
GUISetState(@SW_HIDE, $GUI_ADD)
GUISetState(@SW_HIDE, $GUI_INSERT)

IdleMode()

; Wait, that's all you have to do...
Func IdleMode()
    While 1
   ; endless waiting loop
        Sleep(500)             ; some sleep to be sure not to overload the machine
    WEnd
EndFunc

; Time for some action, user requested to add a new wallpaper
Func AddWP()
    GuiSetState( @SW_SHOW, $GUI_ADD)
    $clipbrdstring = ClipGet()
    If StringInStr($clipbrdstring, "http://") = 1 And (StringInStr($clipbrdstring, ".jpg") = 1 Or StringInStr($clipbrdstring, ".bmp") = 1 Or StringInStr($clipbrdstring, ".gif") = 1) Then
        GUICtrlSetData( $PhotoDownloadURL, $clipbrdstring)
    EndIf
EndFunc

; We're ready to start the download
Func Downloader()
    GUISetState( @SW_HIDE, $GUI_ADD)
    Opt("TrayIconHide", 0)
    $PhotoDownloadURL_Text = GUICtrlRead($PhotoDownloadURL)
    $PhotoFilenamePos = StringInStr($PhotoDownloadURL_Text, "/", 0, -1)
    $PhotoFilenamePos = $PhotoFileNamePos + 1
    $PhotoFilename = StringMid($PhotoDownloadURL_Text, $PhotoFilenamePos)
    GUICtrlSetData($FileName, $PhotoFilename)
    GUISetState( @SW_SHOW, $GUI_INSERT)
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    TrayTip("Wallpaper Manager", "Downloading new wallpaper...", 5, 1)
    InetGet(GUICtrlRead($PhotoDownloadURL), @ScriptDir & "\Wallpapers\" & $PhotoFilename, 0, 0)
    TrayTip("Wallpaper Manager", "Download complete.", 5, 1)
    _ChangeWallpaper(@ScriptDir & "\Wallpapers\" & $PhotoFilename)
    Sleep(5000)
    Opt("TrayIconHide", 1)
    IdleMode()
EndFunc

; Run this after running the file name dialog thingy
Func HideFilenameWindow()
    GUISetState( @SW_HIDE, $GUI_INSERT)
EndFunc

; Run this when users cancels the add process
Func CancelAddWP()
    GUISetState(@SW_HIDE, $GUI_ADD)
    GUISetState(@SW_HIDE, $GUI_INSERT)
EndFunc

; Simple hotkey definition to quit
Func ExitWPD()
    Exit
EndFunc

; Wallpaper changer
Func _ChangeWallpaper($sFile, $iType = 2)
    Local Const $SPI_SETDESKWALLPAPER = 20
    Local Const $SPIF_SENDWININICHANGE = 0x2
; $iType: 1 = Tiled, 2 = Normal size, 3 = Stretched.
    If Not FileExists($sFile) Then Return 0
    If StringTrimLeft($sFile, StringInStr($sFile, '.', 0, -1)) <> 'bmp' Then Return 0
    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')
    EndSelect
    RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
    DllCall("user32", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, "int", 0, "str", $sFile, "int", $SPIF_SENDWININICHANGE)
    Return 1
EndFunc

iPod + Online calendars = iPodCALsync

Link to comment
Share on other sites

Doesn't work here. Probably because of my bad coding skills. :think:
; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Pieter De Decker
;
; Script Function:
;   Adds wallpapers to the Wallpaper directory of Wallpaper Manager
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiConstants.au3>
Break(0)
#NoTrayIcon
Opt("GUIOnEventMode", 1)
HotKeySet("!+d", "AddWP")
HotKeySet("!+x", "ExitWPD")
; Generate Add window
$GUI_ADD = GuiCreate("Add a new wallpaper", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
$PhotoDownloadURL = GuiCtrlCreateInput("http://", 10, 50, 350, 20)
$Introtext = GuiCtrlCreateLabel("Please enter the URL of the wallpaper that you want to add.", 10, 10, 340, 30)
$Btn_OK = GuiCtrlCreateButton("Download", 10, 90, 170, 30)
    GUICtrlSetOnEvent( $Btn_OK, "Downloader")
$Btn_Cancel = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
    GUICtrlSetOnEvent( $Btn_Cancel, "CancelAddWP")
GUISetState(@SW_HIDE, $GUI_ADD)

; Generate Filename window
$GUI_INSERT = GuiCreate("Insert filename", 371, 124,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
$FileName = GuiCtrlCreateInput("", 10, 50, 350, 20)
$Introtext2 = GuiCtrlCreateLabel("Please enter a filename.", 10, 10, 340, 30)
$Btn_OK2 = GuiCtrlCreateButton("Save", 10, 90, 170, 30)
    GUICtrlSetOnEvent($Btn_OK2, "HideFilenameWindow")   
$Btn_Cancel2 = GuiCtrlCreateButton("Cancel", 190, 90, 170, 30)
    GUICtrlSetOnEvent($Btn_Cancel2, "CancelAddWP")

; Hide both windows
GUISetState(@SW_HIDE, $GUI_ADD)
GUISetState(@SW_HIDE, $GUI_INSERT)

IdleMode()

; Wait, that's all you have to do...
Func IdleMode()
    While 1
    ; waiting and checking if the clipboard contains
        $clipbrdstring = ClipGet()
        If IsDeclared("oldclipbrdstring") And $oldclipbrdstring = $clipbrdstring Then
        ; nothing
        ElseIf StringLeft($clipbrdstring, "7") = "http://" And ( StringInStr($clipbrdstring, ".jpg") Or StringInStr($clipbrdstring, ".bmp") Or StringInStr($clipbrdstring, ".gif") ) Then
            $question1 = MsgBox( 36, "Wallpaper Manager", "Do you want to add " & $clipbrdstring & " to your wallpaper library?")
            If $question1 = 6 Then
                Downloader()
                GUICtrlSetData( $PhotoDownloadURL, $clipbrdstring)
            Else
                $oldclipbrdstring = $clipbrdstring
            EndIf
        EndIf
        Sleep(500)             ; some sleep to be sure not to overload the machine
    WEnd
EndFunc

; Time for some action, user requested to add a new wallpaper
Func AddWP()
    GuiSetState( @SW_SHOW, $GUI_ADD)
    $clipbrdstring = ClipGet()
    If StringLeft($clipbrdstring, "7") = "http://" And ( StringInStr($clipbrdstring, ".jpg") Or StringInStr($clipbrdstring, ".bmp") Or StringInStr($clipbrdstring, ".gif") ) Then
        GUICtrlSetData( $PhotoDownloadURL, $clipbrdstring)
    EndIf
EndFunc

; We're ready to start the download
Func Downloader()
    GUISetState( @SW_HIDE, $GUI_ADD)
    Opt("TrayIconHide", 0)
    $PhotoDownloadURL_Text = GUICtrlRead($PhotoDownloadURL)
    $PhotoFilenamePos = StringInStr($PhotoDownloadURL_Text, "/", 0, -1)
    $PhotoFilenamePos = $PhotoFileNamePos + 1
    $PhotoFilename = StringMid($PhotoDownloadURL_Text, $PhotoFilenamePos)
    GUICtrlSetData($FileName, $PhotoFilename)
    GUISetState( @SW_SHOW, $GUI_INSERT)
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    TrayTip("Wallpaper Manager", "Downloading new wallpaper...", 5, 1)
    InetGet(GUICtrlRead($PhotoDownloadURL), @ScriptDir & "\Wallpapers\" & $PhotoFilename, 0, 0)
    TrayTip("Wallpaper Manager", "Download complete.", 5, 1)
    _ChangeWallpaper(@ScriptDir & "\Wallpapers\" & $PhotoFilename)
    Sleep(5000)
    Opt("TrayIconHide", 1)
    IdleMode()
EndFunc

; Run this after running the file name dialog thingy
Func HideFilenameWindow()
    GUISetState( @SW_HIDE, $GUI_INSERT)
EndFunc

; Run this when users cancels the add process
Func CancelAddWP()
    GUISetState(@SW_HIDE, $GUI_ADD)
    GUISetState(@SW_HIDE, $GUI_INSERT)
EndFunc

; Simple hotkey definition to quit
Func ExitWPD()
    Exit
EndFunc

; Wallpaper changer
Func _ChangeWallpaper($sFile, $iType = 2)
    Local Const $SPI_SETDESKWALLPAPER = 20
    Local Const $SPIF_SENDWININICHANGE = 0x2
; $iType: 1 = Tiled, 2 = Normal size, 3 = Stretched.
    If Not FileExists($sFile) Then Return 0
    If StringTrimLeft($sFile, StringInStr($sFile, '.', 0, -1)) <> 'bmp' Then Return 0
    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')
    EndSelect
    RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
    DllCall("user32", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, "int", 0, "str", $sFile, "int", $SPIF_SENDWININICHANGE)
    Return 1
EndFunc

iPod + Online calendars = iPodCALsync

Link to comment
Share on other sites

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Pieter De Decker
;
; Script Function:
;   Adds wallpapers to the Wallpaper directory of Wallpaper Manager
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiConstants.au3>
Break(0)
#NoTrayIcon
Opt("GUIOnEventMode", 1)
HotKeySet("!+d", "AddWP")
HotKeySet("!+x", "ExitWPD")

Global $oldclipbrdstring = ClipGet()
Global $PhotoFilename

; Generate Add window
$GUI_ADD = GUICreate("Add a new wallpaper", 371, 124, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$PhotoDownloadURL = GUICtrlCreateInput("http://", 10, 50, 350, 20)
$Introtext = GUICtrlCreateLabel("Please enter the URL of the wallpaper that you want to add.", 10, 10, 340, 30)
$Btn_OK = GUICtrlCreateButton("Download", 10, 90, 170, 30)
$Btn_Cancel = GUICtrlCreateButton("Cancel", 190, 90, 170, 30)
GUISetState(@SW_HIDE, $GUI_ADD)

; Generate Filename window
$GUI_INSERT = GUICreate("Insert filename", 371, 124, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$FileName = GUICtrlCreateInput("", 10, 50, 350, 20)
$Introtext2 = GUICtrlCreateLabel("Please enter a filename.", 10, 10, 340, 30)
$Btn_OK2 = GUICtrlCreateButton("Save", 10, 90, 170, 30)
$Btn_Cancel2 = GUICtrlCreateButton("Cancel", 190, 90, 170, 30)

GUISetOnEvent($GUI_EVENT_CLOSE, "CancelAddWP")
GUICtrlSetOnEvent($Btn_OK, "Downloader")
GUICtrlSetOnEvent($Btn_Cancel, "CancelAddWP")
GUICtrlSetOnEvent($Btn_OK2, "HideFilenameWindow")
GUICtrlSetOnEvent($Btn_Cancel2, "CancelAddWP")

; Hide both windows
;~ GUISetState(@SW_HIDE, $GUI_ADD)
;~ GUISetState(@SW_HIDE, $GUI_INSERT)

IdleMode()

; Wait, that's all you have to do...
Func IdleMode()
    While 1
    ; waiting and checking if the clipboard contains
        $clipbrdstring = ClipGet()
        If $oldclipbrdstring = $clipbrdstring Then
        ; nothing
        ElseIf StringLeft($clipbrdstring, "7") = "http://" And (StringInStr($clipbrdstring, ".jpg") Or StringInStr($clipbrdstring, ".bmp") Or StringInStr($clipbrdstring, ".gif")) Then
            $question1 = MsgBox(36, "Wallpaper Manager", "Do you want to add " & $clipbrdstring & " to your wallpaper library?")
            If $question1 = 6 Then
                Downloader()
                GUICtrlSetData($PhotoDownloadURL, $clipbrdstring)
            Else
                $oldclipbrdstring = $clipbrdstring
            EndIf
        EndIf
        Sleep(500)            ; some sleep to be sure not to overload the machine
    WEnd
EndFunc  ;==>IdleMode

; Time for some action, user requested to add a new wallpaper
Func AddWP(); shift + alt + d pressed
    GUISetState(@SW_SHOW, $GUI_ADD)
    $clipbrdstring = ClipGet()
    If StringLeft($clipbrdstring, "7") = "http://" And (StringInStr($clipbrdstring, ".jpg") Or StringInStr($clipbrdstring, ".bmp") Or StringInStr($clipbrdstring, ".gif")) Then
        GUICtrlSetData($PhotoDownloadURL, $clipbrdstring)
    EndIf
EndFunc  ;==>AddWP

; We're ready to start the download
Func Downloader(); download button selected
    GUISetState(@SW_HIDE, $GUI_ADD)
    Opt("TrayIconHide", 0)
    $PhotoDownloadURL_Text = GUICtrlRead($PhotoDownloadURL)
    $PhotoFilenamePos = StringInStr($PhotoDownloadURL_Text, "/", 0, -1)
    $PhotoFilenamePos = $PhotoFilenamePos + 1
    $PhotoFilename = StringMid($PhotoDownloadURL_Text, $PhotoFilenamePos)
    GUICtrlSetData($FileName, $PhotoFilename)
    GUISetState(@SW_SHOW, $GUI_INSERT)
EndFunc  ;==>Downloader

; Run this after running the file name dialog thingy
Func HideFilenameWindow(); save button selected
    GUISetState(@SW_HIDE, $GUI_INSERT)
    TrayTip("Wallpaper Manager", "Downloading new wallpaper...", 5, 1)
    InetGet(GUICtrlRead($PhotoDownloadURL), @ScriptDir & "\Wallpapers\" & $PhotoFilename, 0, 0)
    TrayTip("Wallpaper Manager", "Download complete.", 5, 1)
    _ChangeWallpaper(@ScriptDir & "\Wallpapers\" & $PhotoFilename)
    Sleep(5000)
    Opt("TrayIconHide", 1)
EndFunc  ;==>HideFilenameWindow

; Run this when users cancels the add process
Func CancelAddWP(); cancel button selected
    GUISetState(@SW_HIDE, $GUI_ADD)
    GUISetState(@SW_HIDE, $GUI_INSERT)
EndFunc  ;==>CancelAddWP

; Simple hotkey definition to quit
Func ExitWPD(); shift + alt + x pressed
    Exit
EndFunc  ;==>ExitWPD

; Wallpaper changer
Func _ChangeWallpaper($sFile, $iType = 2)
    Local Const $SPI_SETDESKWALLPAPER = 20
    Local Const $SPIF_SENDWININICHANGE = 0x2
; $iType: 1 = Tiled, 2 = Normal size, 3 = Stretched.
    If Not FileExists($sFile) Then Return 0
    If StringTrimLeft($sFile, StringInStr($sFile, '.', 0, -1)) <> 'bmp' Then Return 0
    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')
    EndSelect
    RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
    DllCall("user32", "int", "SystemParametersInfo", "int", $SPI_SETDESKWALLPAPER, "int", 0, "str", $sFile, "int", $SPIF_SENDWININICHANGE)
    Return 1
EndFunc  ;==>_ChangeWallpaper

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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