Jump to content

My Timer


newsak2005
 Share

Recommended Posts

Counter Timer

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

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

_main()
Func _main()
    Local $hForm = GUICreate("CounterTimer Sample", 184, 66, -1, 250, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitApp")
    Local $Lbl_hour = GUICtrlCreateLabel("0", 16, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    GUICtrlCreateLabel(":", 56, 16, 13, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    Local $Lbl_min = GUICtrlCreateLabel("0", 72, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    GUICtrlCreateLabel(":", 112, 16, 13, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    Local $Lbl_sec = GUICtrlCreateLabel("0", 128, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    Local $Lbl_disc = GUICtrlCreateLabel("Please wait: 1 .min", 40, 3, 100, 20, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW)
    Dim $s = 0
    Dim $m = 0
    Dim $h = 0
    While 1
        Local $begin = TimerInit()
        Sleep(1000)
        Local $dif = TimerDiff($begin)
        If $dif Then $s += 1 ;ticktime.
        GUICtrlSetData($Lbl_sec, $s)
        If $s >= 59 Then
            $S = -1
            $m +=1
            GUICtrlSetData($Lbl_min, $m)
        ElseIf $m >= 59  Then
            $m = -1
            $h += 1
            GUICtrlSetData($Lbl_hour, $h)
            If GUICtrlRead($Lbl_hour)=24 Then $h = 0
        EndIf
        If GUICtrlRead($Lbl_min)=1 Then ;set time = 1 .minite ExitApp.
            GUICtrlSetData($Lbl_disc, "Out of time.")
            MsgBox(64, "", "Out of time: for 1 .min ExitApp", 0, $hForm)
            Dim $i
            For $i = 255 To 0 Step -3
                WinSetTrans("CounterTimer Sample", "", $i)
                Sleep(1)
            Next
                ExitLoop
        EndIf
    WEnd ;==> end counter timer.
EndFunc

Func _ExitApp()
    GUIDelete()
    Exit
EndFunc
Edited by newsak2005
Link to comment
Share on other sites

This section isn't very well written:

While 1
        Local $begin = TimerInit()
        Sleep(1000)
        Local $dif = TimerDiff($begin)
        If $dif Then $s += 1 ;ticktime.

You are resetting the value of $begin every time through the loop, $dif is always going to evaluate at TRUE due to the fact it's always going to be greater than 0 so $s is going to get incremented every 1 second so there's no point in using timerinit and timerdiff. If you only want $s to be incremented once a second without the sleep, you need to move the initial TimerInit outside of the While loop and remove the sleep, like this:

Local $begin = TimerInit()
    While 1
        Local $dif = TimerDiff($begin)
        If $dif > 1000 Then 
            $s += 1 ;ticktime.
            $begin = TimerInit()
        EndIf

Or, you can eliminate the whole TimerInit/Diff sequence and just leave the sleep in there, as it will always sleep the script for 1 second.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Also its best to declare variables outside of the loop because it slows it down, that's what I've been told.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

BrewManNH.

Thank you for your help.

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

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

_main()
Func _main()
    Local $hForm = GUICreate("CounterTimer Sample", 184, 66, -1, 250, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitApp")
    Local $Lbl_hour = GUICtrlCreateLabel("0", 16, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    GUICtrlCreateLabel(":", 56, 16, 13, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    Local $Lbl_min = GUICtrlCreateLabel("0", 72, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    GUICtrlCreateLabel(":", 112, 16, 13, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    Local $Lbl_sec = GUICtrlCreateLabel("0", 128, 20, 40, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
    Local $Lbl_disc = GUICtrlCreateLabel("Please wait: 1 .min", 40, 3, 100, 20, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW)
    Dim $s = 0
    Dim $m = 0
    Dim $h = 0
    Local $begin = TimerInit()
    While 1
        Local $dif = TimerDiff($begin)
        If $dif > 1000 Then
            $s += 1 ; new ticktime script.
            $begin = TimerInit()
        GUICtrlSetData($Lbl_sec, $s)
        If $s >= 59 Then
            $S = -1
            $m +=1
            GUICtrlSetData($Lbl_min, $m)
        ElseIf $m >= 59  Then
            $m = -1
            $h += 1
            GUICtrlSetData($Lbl_hour, $h)
            If GUICtrlRead($Lbl_hour)=24 Then $h = 0
        EndIf
        EndIf
        If GUICtrlRead($Lbl_min)=1 Then ;set time = 1 .minite ExitApp.
            GUICtrlSetData($Lbl_disc, "Out of time.")
            MsgBox(64, "", "Out of time: for 1 .min ExitApp", 0, $hForm)
            Dim $i
            For $i = 255 To 0 Step -3
                WinSetTrans("CounterTimer Sample", "", $i)
                Sleep(1)
            Next
                ExitLoop
        EndIf
    WEnd ;==> end counter timer.
EndFunc

Func _ExitApp()
    GUIDelete()
    Exit
EndFunc

===========================================================

SystemClock

Cedit code from guinness.

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

Opt("GUIOnEventMode", 1)

Global $sDate
$Form1 = GUICreate("GUI")
GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitApp")
$Label1 = GUICtrlCreateLabel(_WMIDateStringToDate($sDate), 160, 200, 355, 17)
GUISetState(@SW_SHOW)

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

Func _timer()
    $begin = TimerInit()
    Sleep(1000)
    $dif = TimerDiff($begin)
    If $dif <> 0 Then
        $sDate = _DateToWMIDateString(@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC)
        ControlSetText("GUI", "", "Static1", _WMIDateStringToDate($sDate))
    EndIf
EndFunc

Func _WMIDateStringToDate($sDate)
    Local $sDelimeter = "/"
    Return StringRegExpReplace($sDate, "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\.\d{6}\+\d\d\d", "$3" & $sDelimeter & "$2" & $sDelimeter & "$1  $4:$5:$6") ; jchd's Efficent Version - $10 Is The Number Of Minutes Difference Between Your Local Time And Greenwich Mean Time.
EndFunc   ;==>_WMIDateStringToDate

Func _DateToWMIDateString($sDate)
    Local $iOffSet = 000, $oColFiles, $oWMIService
    $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    $oColFiles = $oWMIService.ExecQuery("Select * From Win32_TimeZone")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            $iOffSet = $oObjectFile.Bias ; Retrieve GMT Offset - http://technet.microsoft.com/en-us/library/ee156558.aspx
        Next
    EndIf
    Return StringRegExpReplace($sDate, "(\d{2})/(\d{2})/(\d{4})\s+(\d{2}):(\d{2}):(\d{2})", "$3$2$1$4$5$6.000000+") & $iOffSet ; jchd's Version.
EndFunc   ;==>_DateToWMIDateString

Func _ExitApp()
    Exit
EndFunc
Edited by newsak2005
Link to comment
Share on other sites

Title Clock. Use AutoItX3 Com Object.

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Date.au3>

Opt("MustDeclareVars", 1)

_DateTime()
Func _DateTime()
    GUICreate('', @DesktopWidth/3-75, @DesktopHeight/4-195, 740, 10, _
    BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS), _
    BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
    GUISetIcon("shell32.dll", 47)
    GUISetState()

    Local $oAutoIt = ObjCreate("AutoItX3.Control")
    Do
        Local $title = $oAutoIt.WinGetTitle('')
        $oAutoIt.WinSetTitle($title, "",_DateDayOfWeek( @WDAY, 1)&' '& _
                                        _DateTimeFormat( _
                                        _NowCalc(), 1)&' '& _
                                        _NowTime())
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc
Edited by newsak2005
Link to comment
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
 Share

  • Recently Browsing   0 members

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