Jump to content

Automatically restore AutoIt-based GUI some time after being minimized


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 post
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 post
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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By It_is_me_Me
      I am making some GUI with combobox for the Baudrates communications and I listed 9600, 57600, 115200. 
      I wrote the code to be defaulted to 57600 like this:
      GUICtrlSetData($comboBox_opticalBaudRate, "9600|57600|115200", "57600")
      But I wanted the GUI to remember the last item the user picks so the baudrates will NOT be defaulted to 57600.
      Example, I pick 9600 as my baudrates, then I close the GUI, after opening it, it always prompt 57600 since that is what I did in my code. But I want that if I choose 9600 and close the GUI, opening it again will show 9600 now instead of 57600.
      Is there a way to do it in GUI setting?
       
      Thanks.
    • By ashraful089
      #include <ButtonConstants.au3>
      #include <ComboConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <WindowsConstants.au3>
      #Region ### START Koda GUI section ### Form=C:\Users\Engr. Ashraful\Videos\koda_1.7.3.0\Forms\ProgramPlayer\FormProgamToOpen.kxf
      $FormInput = GUICreate("Input", 302, 205, 454, 285)
      $Resolution = GUICtrlCreateCombo("Resolution", 80, 24, 145, 25)
      GUICtrlSetData(-1, "1920|VM1920|1366")
      $ComboProgramType = GUICtrlCreateCombo("Program Type Selection", 80, 64, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
      GUICtrlSetData(-1, "Multimedia|Official|Design|Web")
      $ButtonEnter = GUICtrlCreateButton("Enter", 104, 104, 75, 25)
      GUISetState(@SW_SHOW)
      #EndRegion ### END Koda GUI section ###
      While 1
          $nMsg = GUIGetMsg()
          Switch $nMsg
              Case $GUI_EVENT_CLOSE
                  Exit
          EndSwitch
      WEnd
       
      please help me to read combo box input and use the value for another function/ work
       
    • By Aapjuh
      Hi,
      I am having a problem properly saving the Width of a resizable Gui.
      When a user resizes the Gui it gets saved in an ini when the Gui closes to then restore the new Width upon reopening the app.
      with GUICreate("myGui",300,200,Default,Default,$WS_SIZEBOX)
      WinGetPos($hGUI) returns 314, and WinGetClientSize($hGUI) returns 298
      when its then saved in the ini the gui keeps expanding or shrinking every time its opened by +14 or -2
      I figure it has to do with borders etc, but i also guess borders depend on the window theme and whatnot or is user specific, so i can't just do $GuiWidth = $GetGuiWidth[arr] -14 or +2 right?

      is there a proper way of doing this?
      Thanks in advance,
      Aapjuh
    • By It_is_me_Me
      I have provided a portion of my script (seen below) and I wanted to use what the USER will input into my IP address box and input box for TCP port. I set the IP address to use 0.0.0.0 as default and the Port to 502. But I want to let the user change it and when they click the buttons (IP Address and Port), the tooltip will show what the USER entered. How can I use the details that the User will input into my input box and IP address box and let them see what they entered when they click the buttons?
       
      Here are the scripts:
      ;-------------------------------------------------------------
      #include <ButtonConstants.au3>
      #include <ComboConstants.au3>
      #include <EditConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <GuiIPAddress.au3>
      #include <StaticConstants.au3>
      #include <WindowsConstants.au3>
      #include <GuiEdit.au3>
      #include <MsgBoxConstants.au3>
      #include <Date.au3>
      #include <TabConstants.au3>
      #include <GuiTab.au3>

      Global $Form1 = GUICreate("Security Automation", 490, 339, -1, -1)
      ;MAIN Tab
      Global $TAB = GUICtrlCreateTab(0, 0, 489, 337)
      Global $tab_main = GUICtrlCreateTabItem("Main")
      $label_Title = GUICtrlCreateLabel("ETP-073 Security", 12, 33, 103, 17)
      GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
      ;-----------------TCP User input information-------------------------------------------------------------------------------
      $groupBox_TCP = GUICtrlCreateGroup("TCP", 12, 49, 289, 57, BitOR($GUI_SS_DEFAULT_GROUP,$BS_FLAT))
      ;TCP IP address
      Global $IPAddress1 = _GUICtrlIpAddress_Create($Form1, 20, 81, 170, 21)
      $Label_ipAddress = GUICtrlCreateLabel("Host IP Address", 20, 65, 80, 17)
      $userInputIP = _GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
      ;TCP Port
      $label_tcpPort = GUICtrlCreateLabel("Port", 196, 65, 23, 17)
      Global $input_tcpPort = GUICtrlCreateInput("502", 196, 81, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
      $userPort = GUICtrlRead($input_tcpPort)
      ;TCP Address
      $label_tcpAddress = GUICtrlCreateLabel("Addr.", 260, 65, 29, 17)
      Global $input_tcpDevAddress = GUICtrlCreateInput("1", 260, 81, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
      ;Buttons
      Global $btn_userIP = GUICtrlCreateButton("User IP", 308, 297, 81, 25)
      Global $btn_Port = GUICtrlCreateButton("Port", 404, 297, 75, 25)
      ;Showing the GUI
      GUISetState(@SW_SHOW)
      While 1
         $nMsg = GUIGetMsg()
         Switch $nMsg
            Case $GUI_EVENT_CLOSE
               Exit
            Case $btn_userIP
               ToolTip($userInputIP)
            Case $btn_Port
               ToolTip($userPort)
         EndSwitch
      WEnd
      ;--------------end of script ------------------
       
      Note: There will be a "!->Includefile <WMDebug.au3> not found." Pay no attention to it.
    • By llssff
      My current script:
      ```
      $notepadWindow = RunWait('notepad.exe')
      ControlSend($notepadWindow, "Edit1", "", "abcde")
      WinSetState($notepadWindow, "", @SW_MINIMIZE)
      ```
      I can't seem to get these three lines to work. Its supposed to run a notepad window, then enter "abcde", followed by minimizing it. 
      Currently it just opens and nothing happens.
      What am I doing wrong here?
       
       
       
×
×
  • Create New...