Jump to content

Recommended Posts

Posted

hi everybody
today i was going to try out doing a countdown timer coding
where i saw a post about it, in the forum
but on that I could only see the post only involves minutes and seconds as countdown display
I try it out by adding the Hours as well, it works but at one point the GUI created do not show any number displaying for Seconds
hope you could take your time and see this problem.
here's the code:

#include <WindowsConstants.au3>

Global $SS_CENTER, $_CompteArebour = 60000, $_Hours, $_Minutes, $_Seconds

$_GuiCountDown = GUICreate ( "CountDown...", 700, 200, @DesktopWidth/2 -250, @DesktopHeight/2 -100, $WS_EX_TOPMOST  )
GUISetBkColor ( 0xFFFF00 )
$TimeLabel = GUICtrlCreateLabel ( "", 35, -10, 480, 180, $SS_CENTER )
GUICtrlSetFont ( -1, 125, 800 )
GUISetState ( )
WinSetOnTop ( $_GuiCountDown, "", 1)
$TimeTicks = TimerInit ( )

While 1
    _Check ( )
    Sleep ( 200 )
WEnd

Func _Check ( )
    $_CompteArebour -= TimerDiff ( $TimeTicks )
    $TimeTicks = TimerInit ( )
    Local $_HourCalc = Int( $_CompteArebour / ( 60 * 1000 ) ), $_MinCalc =  $_CompteArebour - ( $_HourCalc * 60 * 1000 ), $_SecCalc = $_CompteArebour - ( $_HourCalc * $_MinCalc * 60 * 1000 )
    ;$_MinCalc = Int ( $_MinCalc / 1000 )
    ;Local $_MinCalc = Int ( $_CompteArebour / ( 60 * 1000 ) ), $_SecCalc = $_CompteArebour - ( $_MinCalc * 60 * 1000 )
    $_SecCalc = Int ( $_SecCalc / 1000 )
    If $_HourCalc <= 0 And $_MinCalc <= 0 And $_SecCalc <= 0 Then
        GUISetBkColor ( 0xFF0000, $_GuiCountDown )
        GUICtrlSetData ( $TimeLabel, "Bye !" )
        Sleep ( 1000 )
        ; If @Compiled Then Shutdown ( 13 )
        Exit
    Else
        If $_HourCalc <> $_Hours Or $_MinCalc <> $_Minutes Or $_SecCalc <> $_Seconds Then

            $_Hours = $_HourCalc
            $_Minutes = $_MinCalc
            $_Seconds = $_SecCalc
            GUICtrlSetData ( $TimeLabel, StringFormat ( "%02u" & ":" & "%02u" & ":" & "%02u", $_Hours, $_Minutes, $_Seconds ) )
            If $_Hours =0 And $_Minutes = 0 And $_Seconds <= 10 Then
                Beep ( 1200, 100 )
                GUISetBkColor ( 0xA093FF, $_GuiCountDown )
            EndIf
        EndIf
    EndIf
EndFunc ;==> _Check ( )

 

Posted

.... small simplification

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

Global $_CompteArebour = 60000 ; milliseconds to wait (one minute here)

$_GuiCountDown = GUICreate("CountDown...", 700, 200, @DesktopWidth / 2 - 250, @DesktopHeight / 2 - 100, -1, $WS_EX_TOPMOST)
GUISetBkColor(0xFFFF00)
$TimeLabel = GUICtrlCreateLabel("", 0, 0, 700, 200, $SS_CENTER)
GUICtrlSetFont(-1, 125, 800)
GUISetState()

Global $TimeTicks = TimerInit()

While 1
    _Check()
    Sleep(1000)
WEnd

Func _Check()
    Local $Lapsed = ($_CompteArebour - TimerDiff($TimeTicks)) / 1000 ; seconds lapsed

    Local $_Hours = Floor($Lapsed / 3600)
    Local $_Minutes = Mod(Floor($Lapsed / 60), 60)
    Local $_Seconds = Mod($Lapsed, 60)

    If($_Hours + $_Minutes + $_Seconds) < 0 Then

        GUISetBkColor(0xFF0000, $_GuiCountDown)
        GUICtrlSetData($TimeLabel, "Bye !")
        Sleep(1000)
        Exit

    Else
        GUICtrlSetData($TimeLabel, StringFormat("%02u:%02u:%02u", $_Hours, $_Minutes, $_Seconds))
        If $_Hours = 0 And $_Minutes = 0 And $_Seconds <= 10 Then
            Beep(1200, 100)
            GUISetBkColor(0xA093FF, $_GuiCountDown)
        EndIf
    EndIf
EndFunc   ;==>_Check

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...