I try to crate a stopwatch, but the i have a problem with the FormatTime. if i set hh:mm:ss and start the stopwatch th hour start from 12.
Code: Select all
#NoEnv
Gui, -Caption
Gui, +Sysmenu +ToolWindow
SetBatchLines, -1
SetWinDelay, -1
ElapsedTime := A_YYYY ; initialize ElapsedTime, it will be treated as YYYY0101000000
BalanceTime := 0
Gui, +AlwaysOnTop +HwndGuiHwnd
Gui, Add, Picture, x0 y5 w160 h525, Buttons\bg.png
;Gui, Font, cff3366
Gui, Font, c00ffff
Gui, Add , text, x5 y30 +BackgroundTrans,BÁRKÓD:
;Gui, Add , text, x120 y30 +BackgroundTrans Hidden vREISS,REIS
Gui, Add , DDL, x5 y50 +BackgroundTrans, ATTO|CHAP|VALAMIs
Gui, Add, Picture, x0 y70 +BackgroundTrans, Buttons\v.png
Gui, Add , text, x5 y90 +BackgroundTrans, FOLYAMAT
Gui, Add, DDL, x5 y110 +BackgroundTrans, VALAMI|EZT CSINálom|BLABLA
Gui, Add, Picture, x0 y130 +BackgroundTrans, Buttons\v.png
Gui, Add , text, x5 y150 +BackgroundTrans, Perc
Gui, Add, Edit, x5 y170 +BackgroundTrans,
Gui, Add, Picture, x0 y190 +BackgroundTrans, Buttons\v.png
;Gui, Add , text, x5 y125 +BackgroundTrans Hidden gCZTO vCZTO,CZTO
Gui, Font, c00ffff
Gui, Font, S16 Bold,
Gui, Add , text, x5 y220 +BackgroundTrans vDisplayTime, 00:00:00
Gui, Font,,
Gui, Font, Bold,
Gui, Add, Button, x5 y250 w50 hp vBtnStartStop gStartStop Default, Start ;`nStop
Gui, Add, Button, x+0 y250 w50 hp vBtnReset gReset, Reset
Gui, Add, Button, x+0 y250 w50 hp vBtnRögzít gRögzít, Rögzít
Gui, Show, x0 y-5 w160 h525
Gosub, StartStop
;SetTimer, PressTheKey, 60000
SetTimer, check, 10
MouseMove, 10, 10
Return
check:
SetTimer, check, Off
WinGet, hwnd, ID, A
WinGetPos,x,y,w,h,ahk_id %GuiHwnd%
MouseGetPos,mx,my
if (mx <= 0 && my <= y+h)
gosub ShowWindow
if (hwnd <> GuiHwnd or ((mx > w) or (my > y+h))) {
gosub HideWindow
}
SetTimer, check, 10
return
HideWindow:
WinGetPos,x,y,w,h,ahk_id %GuiHwnd%
while (x+w > 0 ) {
WinMove, ahk_id %GuiHwnd%,,% x-10
WinGetPos,x,y,w,h,ahk_id %GuiHwnd%
Sleep, 10
}
return
ShowWindow:
WinGetPos,x,y,w,h,ahk_id %GuiHwnd%
while (x < 0 ) {
WinMove, ahk_id %GuiHwnd%,,% x+10
WinGetPos,x,y,w,h,ahk_id %GuiHwnd%
Sleep, 10
}
WinActivate, ahk_id %GuiHwnd%,
return
StartStop:
GuiControlGet, BtnStartStop ; get the caption of the button
If (BtnStartStop = "Start"){ ;`nStop") { ; if it is "Start`nStop"
StartTickCount := A_TickCount - BalanceTime ; initialize StartTickCount
SetTimer, StopWatch, 10 ; start the timer called every 10 ms to be accurate
GuiControl, , BtnStartStop, Stop ; set the caption to Stop
} Else { ; it should be "Stop"
BalanceTime := A_TickCount - StartTickCount ; memorize the balance time not counted yet
SetTimer, StopWatch, Off ; stop the timer
; stop the timer
GuiControl, , BtnStartStop, Start ;`nStop ; set the caption to "Start`nStop"
} ; set the caption to "Start`nStop"
Return
; BtnReset label
; BtnReset label
Reset:
SetTimer, StopWatch, Off ; stop the timer
GuiControl, , BtnStartStop, Start ;`nStop ; set the caption of BtnStartStop to "Start`nStop"
GuiControl, , DisplayTime, 00:00:00 ; initialize DisplayTime
ElapsedTime := A_YYYY ; initialize ElapsedTime, it will be treated as YYYY0101000000
BalanceTime := 0 ; initialize BalanceTime
GuiControl, Focus, BtnStartStop ; set the focus on BtnStartStop
GuiControl, -Default, BtnReset ; remove the BS_DEFPUSHBUTTON (default) style
GuiControl, +Default, BtnStartStop ; set the BS_DEFPUSHBUTTON (default) style
Return
StopWatch:
If ((A_TickCount - StartTickCount) >= 1000) { ; if current tickcount - StartTickCount >= 1000 (i.e. 1 second)
StartTickCount += 1000 ; add 1000 ms (1 second) to StartTickCount
ElapsedTime += 1, S ; add 1 second to ElapsedTime
FormatTime, DisplayTime, %ElapsedTime%, hh:mm:ss ; format ElapsedTime to mm:ss
GuiControl, , DisplayTime, %DisplayTime% ; update DisplayTime
}
Return
Rögzít:
return
$1::
return
GuiEscape:
GuiClose:
ExitApp