AdlibRegister("_abort", 100)
#NoTrayIcon
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstants.au3>
$hGUI = GUICreate("Timer", 300, 120)
GUISetFont(16, 800, 0, "Courier New")
$startbutton = GUICtrlCreateButton("Start", 30, 80, 100, 30, $BS_DEFPUSHBUTTON + $BS_FLAT)
$quitbutton = GUICtrlCreateButton("Quit", 170, 80, 100, 30, $BS_FLAT)
Global $h, $m, $s, $hh, $mm, $ss, $hLabel, $h1, $mLabel, $m1, $sLabel
_createIN()
GUICtrlCreateLabel("hour/min/sec", 65, 50, 180, 21)
GUICtrlSetState($startbutton, $GUI_FOCUS)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = -3
Exit
Case $msg = $quitbutton
Exit
Case $msg = $startbutton
$hh = GUICtrlRead($h)
$mm = GUICtrlRead($m)
$ss = GUICtrlRead($s)
If $hh = "" Then $hh = 0
If $mm = "" Then $mm = 0
If $ss = "" Then $ss = 0
If StringIsDigit($hh) And StringIsDigit($mm) And StringIsDigit($ss) Then
If $mm > 59 Or $ss > 59 Then
_error()
Else
GUICtrlSetState($startbutton, $GUI_DISABLE)
_deleteIN()
_createOUT()
$sec = $ss + ($mm)*60 +($hh)*3600
For $i = 0 To $sec
$stimer = TimerInit()
$end = TimerDiff($stimer)
While $end <= 1000
Sleep(10)
$end = TimerDiff($stimer)
WEnd
If $ss = 0 Then
$mm -= 1
If $mm = -1 And $hh <> 0 Then
$hh -= 1
$mm = 59
ElseIf $mm = -1 And $hh = 0 And $ss = 0 Then
$ss = 0
GUICtrlSetData($slabel, "00")
_alarm()
_deleteOUT()
_createIN()
GUICtrlSetState($startbutton, $GUI_ENABLE)
ExitLoop
EndIf
$ss = 60
EndIf
$ss -= 1
GUICtrlSetData($hlabel, StringFormat("%02i", $hh))
If $mm <> 60 Then
GUICtrlSetData($mlabel, StringFormat("%02i", $mm))
Else
GUICtrlSetData($mlabel, "00")
EndIf
If $ss <> 60 Then
GUICtrlSetData($slabel, StringFormat("%02i", $ss))
Else
GUICtrlSetData($slabel, "00")
EndIf
Next
EndIf
Else
_error()
EndIf
EndSelect
WEnd
Func _createIN()
$h = GUICtrlCreateInput("", 80, 15, 36, 30, $ES_NUMBER)
GUICtrlSetData(-1, @HOUR)
GUICtrlSetLimit(-1, 2)
$m = GUICtrlCreateInput("", 130, 15, 36, 30, $ES_NUMBER)
GUICtrlSetData(-1, @MIN)
GUICtrlSetLimit(-1, 2)
$s = GUICtrlCreateInput("", 180, 15, 36, 30, $ES_NUMBER)
GUICtrlSetData(-1, @SEC)
GUICtrlSetLimit(-1, 2)
EndFunc
Func _deleteIN()
GUICtrlDelete($h)
GUICtrlDelete($m)
GUICtrlDelete($s)
EndFunc
Func _createOUT()
$hLabel = GUICtrlCreateLabel(StringFormat("%02i", $hh), 83, 18, 36, 30)
$h1 = GUICtrlCreateLabel(":", 113, 17, 36, 30)
$mLabel = GUICtrlCreateLabel(StringFormat("%02i", $mm), 133, 18, 36, 30)
$m1 = GUICtrlCreateLabel(":", 163, 17, 36, 30)
$sLabel = GUICtrlCreateLabel(StringFormat("%02i", $ss), 183, 18, 36, 30)
EndFunc
Func _deleteOUT()
GUICtrlDelete($hLabel)
GUICtrlDelete($h1)
GUICtrlDelete($mLabel)
GUICtrlDelete($m1)
GUICtrlDelete($sLabel)
EndFunc
Func _error()
MsgBox(0x40040, "Error", "Check inputed data")
EndFunc
Func _abort()
$msg = GUIGetMsg()
If $msg = -3 Or $msg = $quitbutton Then Exit
EndFunc
Func _alarm()
MsgBox(0x40040, "Alarm!", "18/11")
EndFunc