Jump to content
Sign in to follow this  
newsak2005

Init Diff Clock&Timer

Recommended Posts

newsak2005

Init Diff Clock&Timer

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "_hkExit")
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

GUICreate("InitDiffClockTimer", 180, 105, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitApp")
GUICtrlCreateLabel("Clock", 5, 20, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
Local $LC_hour = GUICtrlCreateLabel(@HOUR, 38, 20, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel(":", 75, 16, 10, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
Local $LC_min = GUICtrlCreateLabel(@MIN, 85, 20, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE)) ;clock GUI.
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel(":", 122, 16, 10, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
Local $LC_sec = GUICtrlCreateLabel(@SEC, 133, 20, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")

GUICtrlCreateLabel("Timer", 5, 50, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
Local $LT_hour = GUICtrlCreateLabel(0, 38, 50, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel(":", 75, 50, 10, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
Local $LT_min = GUICtrlCreateLabel(0, 85, 50, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE)) ;timer GUI.
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel(":", 122, 50, 10, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
Local $LT_sec = GUICtrlCreateLabel(0, 133, 50, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

AdlibRegister("_timer")
Do
    Sleep(10)
Until False

Func _timer()
    Local $begin = TimerInit()
    Sleep(1000)
    Local $dif = TimerDiff($begin) ;ticker.
    Dim $s = 0
    Dim $m = 0
    Dim $h = 0
    While 1
        If $dif <> 0 Then
            $s += 1
            GUICtrlSetData($LT_sec, $s)
            GUICtrlSetData($LC_sec, @SEC)
            Sleep($dif)
            If $s = 59 Then
                $s = -1
                $m += 1
                GUICtrlSetData($LT_min, $m) ;timer.
                If $m = 59 Then
                    $m = -1
                    $h += 1
                    GUICtrlSetData($LT_hour, $h)
                    If $h = 23 Then
                        $h = -1
                        GUICtrlSetData($LT_hour, 0)
                    EndIf
                EndIf
            ElseIf @SEC = 0 Then
                GUICtrlSetData($LC_min, @MIN)
                If @MIN = 0 Then
                    GUICtrlSetData($LC_hour, @HOUR) ;clock.
                    If @HOUR = 23 Then
                        GUICtrlSetData($LC_hour, 0)
                    EndIf
                EndIf
            EndIf
        EndIf
    WEnd
EndFunc

Func _ExitApp()
    Exit
EndFunc

Func _hkExit()
    Exit
EndFunc
Edited by newsak2005

Share this post


Link to post
Share on other sites
wakillon

For simplify, you can use GUISetFont instead of repeat 10 times GUICtrlSetFont for each Label, like this :

GUICreate("InitDiffClockTimer", 180, 105, -1, -1)
GUICtrlCreateLabel("Clock", 5, 20, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE)) ; this label keep default font size
GUICtrlCreateLabel("Timer", 5, 50, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE)) ; this one too

GUISetFont ( 24, 800, 0, "MS Sans Serif" )
GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitApp")
Local $LC_hour = GUICtrlCreateLabel(@HOUR, 38, 20, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlCreateLabel(":", 75, 16, 10, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
Local $LC_min = GUICtrlCreateLabel(@MIN, 85, 20, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE)) ;clock GUI.
GUICtrlCreateLabel(":", 122, 16, 10, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
Local $LC_sec = GUICtrlCreateLabel(@SEC, 133, 20, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
Local $LT_hour = GUICtrlCreateLabel(0, 38, 50, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlCreateLabel(":", 75, 50, 10, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
Local $LT_min = GUICtrlCreateLabel(0, 85, 50, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE)) ;timer GUI.
GUICtrlCreateLabel(":", 122, 50, 10, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
Local $LT_sec = GUICtrlCreateLabel(0, 133, 50, 35, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUISetState(@SW_SHOW)

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
newsak2005

wakillon

Thanks For short New GUI. OK

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  

×