Sign in to follow this  
Followers 0
HockeyFan

Help with GUI Timer Countdown

3 posts in this topic

Could someone help me with the following script? I currently have a GUI window that counts down the time in seconds before the window closes. What I would like to do is show the Mintues and Seconds remaining...[Min:Sec] format... instead of just seconds. Would this be an easy conversion?

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3></P> <P>Global $iCountdown = 300

$Form1 = GUICreate("", 633, 350, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS),$WS_EX_WINDOWEDGE)
GUISetBkColor(0x9F79EE
$Label1 = GUICtrlCreateLabel("Mesage header", 10, 10, 596, 50, $SS_CENTER)
GUICtrlSetFont(-1, 20, 800, 0, "Arial")
GUICtrlSetColor(-1,0xffff00);Yellow
$Label2 = GUICtrlCreateLabel(Message Text...' & @CRLF & @CRLF & "and then click the OK button below.", 20, 58, 590, 170)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$Label3 = GUICtrlCreateLabel("(Message Note)", 20, 228, 588, 25, $SS_CENTER)
GUICtrlSetFont(-1, 12, 800, 6, "Arial")
GUICtrlSetColor(-1, 0x00008B);Dark Blue
$Button = GUICtrlCreateButton("OK", 240, 265, 145, 41, 0)
$Label4 = GUICtrlCreateLabel("                This Window will automatically close and continue the installation in 5 minutes.  Time:  " & $iCountdown, 24, 325, 588, 25)
GUISetState(@SW_SHOW)

_Timer_SetTimer($Form1, 1000, '_Countdown')
While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $Button
   Exit
 EndSwitch
WEnd

Func _Countdown($hWnd, $iMsg, $iIDTimer, $dwTime)
    $iCountdown -= 1
    If $iCountdown > 0 Then
        GUICtrlSetData($Label4, "                 This Window will automatically close and continue the installation in 5 minutes.  Time:  " & $iCountdown)
    ElseIf $iCountdown = 0 Then
        _Timer_KillTimer($hWnd, $iIDTimer)
        ControlClick($Form1, '', $Button)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites



Like this?

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <Date.au3>

Global $iCountdown = 300

$Form1 = GUICreate("", 633, 350, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE)
GUISetBkColor(0x9F79EE)
$Label1 = GUICtrlCreateLabel("Mesage header", 10, 10, 596, 50, $SS_CENTER)
GUICtrlSetFont(-1, 20, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xffff00);Yellow
$Label2 = GUICtrlCreateLabel('Message Text...' & @CRLF & @CRLF & "and then click the OK button below.", 20, 58, 590, 170)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$Label3 = GUICtrlCreateLabel("(Message Note)", 20, 228, 588, 25, $SS_CENTER)
GUICtrlSetFont(-1, 12, 800, 6, "Arial")
GUICtrlSetColor(-1, 0x00008B);Dark Blue
$Button = GUICtrlCreateButton("OK", 240, 265, 145, 41, 0)
$Label4 = GUICtrlCreateLabel("                This Window will automatically close and continue the installation in 5 minutes.  Time:  " & _SecsToTime($iCountdown), 24, 325, 588, 25)
GUISetState(@SW_SHOW)

_Timer_SetTimer($Form1, 1000, '_Countdown')
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button
            Exit
    EndSwitch
WEnd

Func _Countdown($hWnd, $iMsg, $iIDTimer, $dwTime)
    $iCountdown -= 1
    If $iCountdown > 0 Then
        GUICtrlSetData($Label4, "                 This Window will automatically close and continue the installation in 5 minutes.  Time:  " & _SecsToTime($iCountdown))
    ElseIf $iCountdown = 0 Then
        _Timer_KillTimer($hWnd, $iIDTimer)
        ControlClick($Form1, '', $Button)
    EndIf
EndFunc  ;==>_Countdown

Func _SecsToTime($iSecs)
    Local $iHours, $iMins, $iSec_s
    _TicksToTime($iSecs*1000,$iHours,$iMins,$iSec_s)
    Return StringFormat("%02i:%02i",$iMins, $iSec_s)
EndFunc

Share this post


Link to post
Share on other sites

Like this?

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <Date.au3>

Global $iCountdown = 300

$Form1 = GUICreate("", 633, 350, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE)
GUISetBkColor(0x9F79EE)
$Label1 = GUICtrlCreateLabel("Mesage header", 10, 10, 596, 50, $SS_CENTER)
GUICtrlSetFont(-1, 20, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xffff00);Yellow
$Label2 = GUICtrlCreateLabel('Message Text...' & @CRLF & @CRLF & "and then click the OK button below.", 20, 58, 590, 170)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$Label3 = GUICtrlCreateLabel("(Message Note)", 20, 228, 588, 25, $SS_CENTER)
GUICtrlSetFont(-1, 12, 800, 6, "Arial")
GUICtrlSetColor(-1, 0x00008B);Dark Blue
$Button = GUICtrlCreateButton("OK", 240, 265, 145, 41, 0)
$Label4 = GUICtrlCreateLabel("                This Window will automatically close and continue the installation in 5 minutes.  Time:  " & _SecsToTime($iCountdown), 24, 325, 588, 25)
GUISetState(@SW_SHOW)

_Timer_SetTimer($Form1, 1000, '_Countdown')
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button
            Exit
    EndSwitch
WEnd

Func _Countdown($hWnd, $iMsg, $iIDTimer, $dwTime)
    $iCountdown -= 1
    If $iCountdown > 0 Then
        GUICtrlSetData($Label4, "                 This Window will automatically close and continue the installation in 5 minutes.  Time:  " & _SecsToTime($iCountdown))
    ElseIf $iCountdown = 0 Then
        _Timer_KillTimer($hWnd, $iIDTimer)
        ControlClick($Form1, '', $Button)
    EndIf
EndFunc ;==>_Countdown

Func _SecsToTime($iSecs)
    Local $iHours, $iMins, $iSec_s
    _TicksToTime($iSecs*1000,$iHours,$iMins,$iSec_s)
    Return StringFormat("%02i:%02i",$iMins, $iSec_s)
EndFunc
Nahuel,

Awesome! :) This is exactly what I needed, Thank you so much! :)

Share this post


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