Jump to content

Recommended Posts

Posted

Hi,

I have a bit of a situation with my GUI, i need to automatically close the GUI after a period of inactivity lets say 15 minutes of not being used??

Is this possible?

Thanks

Nav

Posted

Hi,

Here is a way of doing it, have a TimerInit() before the start of the windows msg loop, check for it reaching a idle maximum duration as one of the cases, after any other case reset the timmer. i made a little example that has two button that will reset the timmer and a status to show the idle time in seconds.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

_Form1()

Func _Form1()
    #Region ### START Koda GUI section ### Form=
    Local $Form1 = GUICreate("Form1", 196, 94, -1, -1)
    Local $hButton1 = GUICtrlCreateButton("Button1", 20, 24, 75, 25)
    Local $hButton2 = GUICtrlCreateButton("Button2", 100, 24, 75, 25)
    Local $hStatusBar1 = _GUICtrlStatusBar_Create($Form1)
    _GUICtrlStatusBar_SetSimple($hStatusBar1)
    _GUICtrlStatusBar_SetText($hStatusBar1, "Idle Time: ")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    Local $iTimmer = TimerInit()
    Local $iTimmerDuraction = 20000
    Local $sStatusText

    While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $GUI_EVENT_CLOSE
                Exit
            Case $nMsg = $hButton1
                MsgBox(0, "Button1", "Idle timmer reset")
                $iTimmer = TimerInit()
            Case $nMsg = $hButton2
                MsgBox(0, "Button2", "Idle timmer reset")
                $iTimmer = TimerInit()
            Case TimerDiff($iTimmer) >= $iTimmerDuraction
                MsgBox(0, "Times up", "Idle time limit reached")
                ExitLoop
            Case Else
                Local $sNewTimeText = "Idle Time: " & Round(TimerDiff($iTimmer) / 1000)
                If $sStatusText <> $sNewTimeText Then
                    $sStatusText = $sNewTimeText
                    _GUICtrlStatusBar_SetText($hStatusBar1, $sStatusText)
                EndIf
        EndSelect
    WEnd
EndFunc   ;==>_Form1
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
  • 13 years later...

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.
×
×
  • Create New...