#Region Directives
; #AutoIt3Wrapper_icon=your_icon.ico
#EndRegion
#Region About
#cs
Title: Settable Clocks with ms
Filename: ----
Description: Show digit clocks in real time. Able to set hour or sync with system time.
Authors: CreatoR (original)
HH (verification, sync with sys clock if needed, combo box)
Forum Topic: http://autoit-script.ru/index.php?topic=26662.0
Version: 1.03 (8 March 2019)
Requirements: AutoIt v3.3 +
Uses: None
Notes: -
#ce
#EndRegion
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <Timers.au3>
#include <Date.au3>
Global $sConfig_File = StringTrimRight(@ScriptFullPath, 3) & 'ini'
Global $iLast_Timer = Int(IniRead($sConfig_File, 'Main', 'Last Timer', 0))
Global $sLast_Time = IniRead($sConfig_File, 'Main', 'Last Time', '')
Global $aHours[24] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
$sHours = ""
For $i = 0 To UBound($aHours) - 1
$sHours &= "|" & $aHours[$i]
Next
$sLast_Time = ($sLast_Time ? $sLast_Time : StringFormat('%02d:%02d:%02d', @HOUR, @MIN, @SEC))
$hGUI = GUICreate('Settable Clock', 220, 150)
Global $iClock_Lbl = GUICtrlCreateLabel(_GetTime(), 15, 25, 100) ; отображение времени
GUICtrlSetFont($iClock_Lbl, 12, 800)
GUICtrlCreateLabel('Set hour:', 125, 10)
GUICtrlCreateLabel('Website: ', 15, 130)
$hCombo = GUICtrlCreateCombo('', 125, 25, 50, 20, $CBS_DROPDOWNLIST + $WS_VSCROLL + $ES_NUMBER)
GUICtrlSetData($hCombo, $sHours, $aHours[0])
$iSetTime_Bttn = GUICtrlCreateButton('Ok', 180, 20, 30, 28)
$iSysTime_Bttn = GUICtrlCreateButton('Sys time', 15, 50, 70, 20)
$iModTimer_Bttn = GUICtrlCreateButton('Timer', 15, 80, 70, 20)
$iIncTimer_Bttn = GUICtrlCreateButton('+1m', 95, 80, 70, 20)
GUISetState(@SW_SHOW, $hGUI)
; If $iLast_Timer Then
; ConsoleWrite(StringTrimLeft(_DateAdd('s', Int(_Timer_Diff($iLast_Timer) / 1000), '1999/01/01 ' & $sLast_Time), 11) & '.' & @MSEC)
; EndIf
$iTimer = _Timer_SetTimer($hGUI, 50, '_UpdateClock')
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_Timer_KillTimer($hGUI, $iTimer)
IniWrite($sConfig_File, 'Main', 'Last Timer', _Timer_Init())
IniWrite($sConfig_File, 'Main', 'Last Time', StringTrimRight(GUICtrlRead($iClock_Lbl), 4))
Exit
Case $iSetTime_Bttn
$sNewTime = StringFormat('%02d:%s', GUICtrlRead($hCombo), StringMid(GUICtrlRead($iClock_Lbl), 4, 5))
ConsoleWrite(StringMid(GUICtrlRead($iClock_Lbl), 4, 5) & @CRLF)
If Not StringRegExp($sNewTime, '^([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$') Then
MsgBox(48, @ScriptName, 'Wrong time format.')
ContinueLoop
EndIf
$iLast_Timer = _Timer_Init()
_UpdateTime($sNewTime)
Case $iSysTime_Bttn
$sNewTime = _GetSysTime()
ConsoleWrite(_GetSystime() & ' --- ' & $sNewTime & @CRLF)
_UpdateTime($sNewTime)
Case $iModTimer_Bttn
$sNewTime = StringFormat('%02d:%02d:%02d.%03d', 00, 00, 00, 000)
ConsoleWrite($sNewTime & @CRLF) ; log
$iLast_Timer = _Timer_Init()
_UpdateTime($sNewTime)
Case $iIncTimer_Bttn
; This should add 1 minute to timer, but while does nothing
EndSwitch
WEnd
Func _UpdateTime($sNewTime)
ConsoleWrite($iLast_Timer & @CRLF) ; Log
$sLast_Time = $sNewTime
GUICtrlSetData($iClock_Lbl, $iLast_Timer)
EndFunc
Func _GetSysTime()
Return StringFormat('%02d:%02d:%02d.%03d', @HOUR, @MIN, @SEC, @MSEC)
EndFunc
Func _GetTime()
If $iLast_Timer Then
$sThisStarted = false
Return StringTrimLeft(_DateAdd('s', Int(_Timer_Diff($iLast_Timer) / 1000), '1999/01/01 ' & $sLast_Time), 11) & '.' & @MSEC
EndIf
Return StringFormat('%02d:%02d:%02d.%03d', @HOUR, @MIN, @SEC, @MSEC)
EndFunc
Func _UpdateClock($hWnd, $Msg, $iIDTimer, $dwTime) ; $hWnd, $Msg, $iIDTimer, $dwTime - reserved
GUICtrlSetData($iClock_Lbl, _GetTime())
EndFunc