#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SliderConstants.au3>
#include <Date.au3>
;Align for horizontal slider
Global Enum _
$STIME_ALIGN_LEFTBOTTOM, _ ;Align time label to the left bottom corner of slider control
$STIME_ALIGN_RIGHTBOTTOM, _ ;Align time label to the right bottom corner of the slider control
$STIME_ALIGN_LEFT, _ ;Align time label to the left side of the slider control
$STIME_ALIGN_RIGHT, _ ;Align time label to the right side of the slider control
$STIME_ALIGN_LEFTTOP, _ ;Align time label to the left top corner of the slider control
$STIME_ALIGN_RIGHTTOP ;Align time label to the right top corner of the slider control
;Align for vertical slider
Global Enum _
$STIME_ALIGN_TOP, _ ;Align time label to the top of slider control
$STIME_ALIGN_BOTTOM ;Align time label to the bottom of slider control
Global Enum $iSTime_hWnd, $iSTime_Slider, $iSTime_Label, _
$iSTime_Total
Global $aSTime[1][$iSTime_Total]
Global Const $sSTime_Delim = __GUICtrlSliderTime_GetTimeDelim(_NowTime())
$hGUI = GUICreate('_GUICtrlSliderTime_Create', 220, 330)
$iTime1_CB = GUICtrlCreateCheckbox('Time 1:', 10, 20, -1, 20)
$iSliderTime1 = _GUICtrlSliderTime_Create($hGUI, 10, 50, 25, 180, '00:00', $STIME_ALIGN_TOP, True)
_GUICtrlSliderTime_SetTime($iSliderTime1, '12:00')
_GUICtrlSliderTime_SetState($iSliderTime1, $GUI_DISABLE)
$iTime2_CB = GUICtrlCreateCheckbox('Time 2:', 10, 250, -1, 20)
GUICtrlSetState($iTime2_CB, $GUI_CHECKED)
$iSliderTime2 = _GUICtrlSliderTime_Create($hGUI, 10, 270, 200, 20, '', $STIME_ALIGN_RIGHTBOTTOM, False)
;~ _GUICtrlSliderTime_SetTime($iSliderTime2, '20:00')
GUISetState(@SW_SHOW, $hGUI)
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
Exit
Case $iTime1_CB, $iTime2_CB
_GUICtrlSliderTime_SetState( _
($iMsg = $iTime1_CB ? $iSliderTime1 : $iSliderTime2), _
(GUICtrlRead($iMsg) = $GUI_CHECKED ? $GUI_ENABLE : $GUI_DISABLE))
EndSwitch
WEnd
Func _GUICtrlSliderTime_Create($hWnd, $iLeft, $iTop, $iWidth, $iHeight = -1, $sTime = Default, $iAlign = 0, $fVert = False)
$sTime = StringReplace($sTime, ':', $sSTime_Delim)
If Not __GUICtrlSliderTime_IsValidTime($sTime) Then
$sTime = @HOUR & $sSTime_Delim & @MIN
EndIf
If $aSTime[0][0] = 0 Then
GUIRegisterMsg($WM_HSCROLL, '__GUICtrlSliderTime_WM_HVSCROLL')
GUIRegisterMsg($WM_VSCROLL, '__GUICtrlSliderTime_WM_HVSCROLL')
EndIf
If $iHeight == Default Or $iHeight = -1 Then
$iHeight = 20
EndIf
Local $iLbl_Left = $iLeft, $iLbl_Top = $iTop
Local $iStyle = $TBS_AUTOTICKS
If $fVert Then
Switch $iAlign
Case $STIME_ALIGN_BOTTOM
$iLbl_Left = $iLeft
$iLbl_Top = ($iTop + $iHeight)
Case Else ;$STIME_ALIGN_TOP
$iTop += 15
EndSwitch
$iStyle = BitOR($iStyle, $TBS_VERT, $TBS_BOTH)
Else
Switch $iAlign
Case $STIME_ALIGN_RIGHTBOTTOM
$iLbl_Left = ($iWidth - 22)
$iLbl_Top = ($iTop + $iHeight)
Case $STIME_ALIGN_LEFT
$iWidth -= 30
$iLbl_Left = $iLeft
$iLeft += 30
$iLbl_Top = $iTop
Case $STIME_ALIGN_RIGHT
$iWidth -= 30
$iLbl_Left = ($iLeft + $iWidth)
$iLbl_Top = $iTop
Case $STIME_ALIGN_LEFTTOP
$iLbl_Left = $iLeft
$iLbl_Top = $iTop
$iTop += 15
Case $STIME_ALIGN_RIGHTTOP
$iLbl_Left = ($iWidth - 22)
$iLbl_Top = $iTop
$iTop += 15
Case Else ;$STIME_ALIGN_LEFTBOTTOM
$iLbl_Left = ($iLeft + 5)
$iLbl_Top = ($iTop + $iHeight)
EndSwitch
EndIf
$aSTime[0][0] += 1
ReDim $aSTime[$aSTime[0][0] + 1][$iSTime_Total]
$aSTime[$aSTime[0][0]][$iSTime_hWnd] = $hWnd
$aSTime[$aSTime[0][0]][$iSTime_Slider] = GUICtrlCreateSlider($iLeft, $iTop, $iWidth, $iHeight, $iStyle)
$aSTime[$aSTime[0][0]][$iSTime_Label] = GUICtrlCreateLabel($sTime, $iLbl_Left, $iLbl_Top, 30, 15)
GUICtrlSetLimit($aSTime[$aSTime[0][0]][$iSTime_Slider], 1440, 0)
_GUICtrlSliderTime_SetTime($aSTime[0][0], $sTime)
Return $aSTime[0][0]
EndFunc
Func _GUICtrlSliderTime_SetTime($iSTime, $sTime = '')
Local $iST_ID = 0
For $iID = 1 To $aSTime[0][0]
If $iID = $iSTime Then
$iST_ID = $iSTime
EndIf
Next
If Not $iST_ID Then
Return SetError(1, 0, 0)
EndIf
$sTime = StringReplace($sTime, ':', $sSTime_Delim)
If __GUICtrlSliderTime_IsValidTime($sTime) Then
Local $aTime = StringSplit($sTime, $sSTime_Delim)
GUICtrlSetData($aSTime[$iSTime][$iSTime_Slider], (_TimeToTicks($aTime[1], $aTime[2], 0) / 60 / 999.9))
Else
Local $iHours, $iMins, $iSecs
$sTime = GUICtrlRead($aSTime[$iSTime][$iSTime_Slider])
$sTime = _TicksToTime($sTime * 60 * 999.9, $iHours, $iMins, $iSecs)
$sTime = StringFormat('%02i' & $sSTime_Delim & '%02i', $iHours, $iMins)
EndIf
GUICtrlSetData($aSTime[$iSTime][$iSTime_Label], $sTime)
EndFunc
Func _GUICtrlSliderTime_SetState($iSTime, $iState)
For $iID = 1 To $aSTime[0][0]
If $iID = $iSTime Then
GUICtrlSetState($aSTime[$iSTime][$iSTime_Slider], $iState)
GUICtrlSetState($aSTime[$iSTime][$iSTime_Label], $iState)
ExitLoop
EndIf
Next
EndFunc
Func __GUICtrlSliderTime_GetTimeDelim($sNowTime)
Local $sDelim = RegRead('HKEY_CURRENT_USER\Control Panel\International', 'sTime')
If $sDelim = '' And StringLen($sNowTime) >= 1 Then
$aTime = StringSplit($sNowTime, '')
For $i = 1 To $aTime[0]
If Not Number($aTime[$i]) Then
$sDelim &= $aTime[$i]
EndIf
If $sDelim <> '' And Number($aTime[$i]) Then
ExitLoop
EndIf
Next
EndIf
Return $sDelim
EndFunc
Func __GUICtrlSliderTime_IsValidTime($sTime)
Return StringRegExp($sTime, '^(?:0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$')
EndFunc
Func __GUICtrlSliderTime_WM_HVSCROLL($hWnd, $iMsg, $wParam, $lParam)
For $i = 1 To $aSTime[0][0]
If $lParam = GUICtrlGetHandle($aSTime[$i][$iSTime_Slider]) Then
_GUICtrlSliderTime_SetTime($i)
ExitLoop
EndIf
Next
Return $GUI_RUNDEFMSG
EndFunc