Jump to content

Automatically restore AutoIt-based GUI some time after being minimized


TXTechie
 Share

Recommended Posts

Hello Everyone,

I've developed my own GUI using AutoIt and I'm allowing users to minimize the GUI, but I also want to include some kind of timer so that it will automatically restore the GUI after something like 30 minutes or an hour. However, I also want them to be able to manually restore the GUI by clicking the application's icon in the taskbar.

I've searched through the forums, but I'm not sure how to get started.

Any ideas or functions to research are appreciated!

Regards,

TX Techie

Edited by TXTechie
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>


; Create a GUI with various controls.
Global $hGUI = GUICreate("Example", 300, 100, -1, -1)
Global $idOK = GUICtrlCreateButton("OK", 10, 70, 85, 25)

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)

Global $iTimeRestoreWindowsEG_1 = 5000
Global $iTimeRestoreWindowsEG_2 = 2500
AdlibRegister("_RestoreWindows_EG_1", $iTimeRestoreWindowsEG_1)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $idOK
            MsgBox(0, "", "OK Press")
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            ConsoleWrite('$GUI_EVENT_MINIMIZE' & @CRLF)
            GUISetState(@SW_MINIMIZE, $hGUI)
            AdlibRegister("_RestoreWindows_EG_2", $iTimeRestoreWindowsEG_2)
    EndSwitch
WEnd

Func _RestoreWindows_EG_1()
    ConsoleWrite('_RestoreWindows_EG_1()' & @CRLF)
    GUISetState(@SW_RESTORE, $hGUI)
EndFunc   ;==>_RestoreWindows_EG_1


Func _RestoreWindows_EG_2()
    ConsoleWrite('_RestoreWindows_EG_2()' & @CRLF)
    GUISetState(@SW_RESTORE, $hGUI)
    AdlibUnRegister("_RestoreWindows_EG_2")
EndFunc   ;==>_RestoreWindows_EG_2

 

Regards,
 

Link to comment
Share on other sites

F1

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

; Create a GUI with various controls.
Global $hGUI = GUICreate("Example", 300, 100, -1, -1)
Global $idOK = GUICtrlCreateButton("OK", 10, 70, 85, 25)
GUICtrlSetOnEvent(-1, "OK_Pressed")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)

Global $iTimeRestoreWindowsEG_1 = 5000
Global $iTimeRestoreWindowsEG_2 = 2500
AdlibRegister("_RestoreWindows_EG_1", $iTimeRestoreWindowsEG_1)


; Loop until the user exits.
While 1
;~  Switch GUIGetMsg()
;~      Case $idOK
;~          OK_Pressed()
;~      Case $GUI_EVENT_CLOSE
;~          ConsoleWrite('$GUI_EVENT_CLOSE' & @CRLF)
;~          Exit
;~      Case $GUI_EVENT_MINIMIZE
;~          ConsoleWrite('$GUI_EVENT_MINIMIZE' & @CRLF)
;~          GUISetState(@SW_MINIMIZE, $hGUI)
;~          AdlibRegister("_RestoreWindows_EG_2", $iTimeRestoreWindowsEG_2)
;~  EndSwitch
WEnd


Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            ConsoleWrite('$GUI_EVENT_CLOSE' & @CRLF)
            Exit

        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
            ConsoleWrite('$GUI_EVENT_MINIMIZE' & @CRLF)
            GUISetState(@SW_MINIMIZE, $hGUI)
            AdlibRegister("_RestoreWindows_EG_2", $iTimeRestoreWindowsEG_2)

        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
            MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

    EndSelect
EndFunc   ;==>SpecialEvents

Func OK_Pressed()
    ConsoleWrite('OK_Pressed()' & @CRLF)
    MsgBox(0, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc   ;==>OK_Pressed

Func _RestoreWindows_EG_1()
    ConsoleWrite('_RestoreWindows_EG_1()' & @CRLF)
    GUISetState(@SW_RESTORE, $hGUI)
EndFunc   ;==>_RestoreWindows_EG_1


Func _RestoreWindows_EG_2()
    ConsoleWrite('_RestoreWindows_EG_2()' & @CRLF)
    GUISetState(@SW_RESTORE, $hGUI)
    AdlibUnRegister("_RestoreWindows_EG_2")
EndFunc   ;==>_RestoreWindows_EG_2

 

Regards,
 

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

×
×
  • Create New...