Jump to content
Sign in to follow this  
CyberSlug

MsgBox with countdown (GUI)

Recommended Posts

CyberSlug

Maybe you will find this useful. It's essentially a GUI for a MsgBox that shows the number of seconds remaining in the timeout.

Tested with a recent-ish AutoIt-GUI Unstable. There is lots of room for improvement; I didn't find anything like this before when I searched the forums, but I thought I had seen one earlier :D

#cs - ### Generated by AutoBuilder 0.4 -- do not modify ###
348 173
0   2   0   0   0   0   0   0   0   1   0   0   0   0   0   0   
label   $label_1    Label 1 10  10  330 40  0   0   
button  $button_1   Button 1    10  90  120 40  0   0   
button  $button_2   Button 2    210 90  120 40  0   0   
#ce - ### End of Dump ###

; Syntax
;   TimedMsgBox( flag, "title", "text" [, timeout] )
;-------

$text = "Session has been idle for X minutes..." & @LF & "Unless you click 'Keep Alive', you will be logged out in "
$retVal = TimedMsgBox(0, "Session Expiring...", $text, 10) ;10 second timeout
If $retVal = 1 Then
   MsgBox(4096,"", "Session expired; you were logged-off.")
Else
   MsgBox(4096,"", "Staying Alive!")
EndIf
Exit

Func TimedMsgBox($flag, $title, $text, $timeout)
   
   Dim $LOGOUT = 1
   Dim $KEEP_ALIVE = 2
   
   Opt("GUINotifyMode", 1)
   GuiCreate("Session Expiring...", 346,168,(@DesktopWidth-346)/2, (@DesktopHeight-168)/2 , 0x04CF0000)
   
   $label_1 = GUISetControl("label", "Label 1", 10, 30, 330, 40)
   $button_1 = GUISetControl("button", "Logout", 10, 90, 120, 40)
   $button_2 = GUISetControl("button", "Keep Alive", 210, 90, 120, 40)
   
   GuiShow()
   GuiWrite($label_1,0, $text  & $timeout & " seconds. ")
   
   $start = TimerStart()
   While 1
       sleep(50)
       
       If TimerStop($start) > 1000 Then
         $start = TimerStart()
         $timeout = $timeout - 1
         $unit = " seconds."
         If $timeout = 1 Then $unit = " second."
         GuiWrite($label_1,0, "Session has been idle for X minutes..." & @LF & "Unless you click 'Keep Alive', you will be logged out in " & $timeout & $unit)
      EndIf
       
     ; you can change this to <= 0 instead of just < 0 
      If $timeout < 0 Then
         GuiDelete()
         Return $LOGOUT
         ExitLoop
      EndIf
   
      $msg = GuiMsg(0)
      Select
      Case $msg = $button_1
         GuiDelete() 
         Return $LOGOUT
      Case $msg = $button_2
         GuiDelete() 
         Return $KEEP_ALIVE
       EndSelect
   WEnd
   Exit
EndFunc

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
Chetwood

Tested with a recent-ish AutoIt-GUI Unstable.

Which version is it and where did you download it from exactly? The latest version I found on http://www.autoitscript.com/autoit3/files/unstable was 3.0.103.0 and when I run your script I get an error message: Unknown function GuiSetControl. I couldn't find any 'TimedMsgBox' or 'TimerStart' in the AutoIt.chm from that directory either. What am I missing?

I've tried to make a countdown window myself but since I'm using the Sleep command the script hjalts for a complete seconds during whcih you can't press the Cancel-button, duh.

GUICreate("Shutdown", 135, 80) 
$Cancel = GUICtrlCreateButton("Cancel", 80,40,50)
GUISetState()     ; created windows are initially hidden, now it's made visible
GUICtrlCreateLabel ( "seconds left", 30, 10, 150)

$i = 60
Do
   GUICtrlCreateLabel ( $i, 15, 10, 15)
   $i = $i -1
   $msg = GUIGetMsg()
      Select
         Case $msg = -3
            ExitLoop
         Case $msg = $Cancel
         Exit
      EndSelect
   Sleep(1000)
 Until $i = 0

MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller √úbersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites
SlimShady

That was 4 months ago.

As Jon said:

The GUI creation features of AutoIt are currently only available in the beta release of AutoIt.

http://www.autoitscript.com/autoit3/files/unstable/autoit/

Please note, the GUI functions are under constant and extensive change at the moment and as such your scripts will break when changes are made.

<{POST_SNAPBACK}>

The changes are made and that's the reason the script doesn't work.

Share this post


Link to post
Share on other sites
Chetwood

The changes are made and that's the reason the script doesn't work.

<{POST_SNAPBACK}>

Right, any other way to do it with functions currently available? Like I said, my given example almost works :) Edited by Chetwood

MultiMakeMKV: batch processing for MakeMKV (Win)MultiShrink: batch processing for DVD ShrinkOffizieller √úbersetzer von DVD Shrink deutsch

Share this post


Link to post
Share on other sites
SlimShady

GUICreate("Shutdown", 135, 80) 
$Cancel = GUICtrlCreateButton("Cancel", 80,40,50)
GUISetState()    ; created windows are initially hidden, now it's made visible
GUICtrlCreateLabel ( "seconds left", 30, 10, 150)
$Remain_label = GUICtrlCreateLabel ("0", 15, 10, 15)

$OldSec = @SEC
$Elapsed = 0
$StartTime = TimerInit()
Do
  If $OldSec <> @SEC Then
     GUICtrlSetData ($Remain_label, 60 - $Elapsed)
     $OldSec = @SEC
  EndIf
  $i = $i - 1
  $msg = GUIGetMsg()
     Select
        Case $msg = -3
           ExitLoop
        Case $msg = $Cancel
        Exit
     EndSelect
  $Elapsed = TimerDiff($StartTime) / 1000
  $Elapsed = Round($Elapsed)
Until $Elapsed = 60

Share this post


Link to post
Share on other sites
BrettF

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
Sign in to follow this  

×