Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stop watch?
#1
Anyway to embed a stop watch in a dialog?

Start button, stop button and lap button.
#2
Function dialog_stop_watch
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "7"
str e7
if(!ShowDialog("dialog_stop_watch" &dialog_stop_watch &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Button 0x54032000 0x0 4 4 48 14 "Start"
;4 Button 0x5C032000 0x0 4 22 48 14 "Stop"
;5 Button 0x54032000 0x0 4 40 48 14 "Reset"
;6 Static 0x54000000 0x0 58 6 68 12 ""
;7 Edit 0x54230844 0x20000 56 22 70 60 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
;messages
int-- t_running
long-- t_startTime
str s
str-- t_results
sel message
,case WM_INITDIALOG
,
,case WM_TIMER
,sel wParam
,,case 1
,,s=TimeSpanToStr(perf-t_startTime*10 2)
,,s.setwintext(id(6 hDlg))
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3 ;;Start/Lap
,if !t_running ;;start
,,t_running=1
,,t_startTime=perf
,,SetTimer hDlg 1 100 0
,,EnableWindow id(4 hDlg) 1
,,s="Lap"; s.setwintext(lParam)
,else ;;lap
,,s=TimeSpanToStr(perf-t_startTime*10 2)
,,t_results.addline(s 1); t_results.setwintext(id(7 hDlg)); SendMessage id(7 hDlg) WM_VSCROLL SB_BOTTOM 0
,,t_startTime=perf
,
,case 4 ;;Stop
,if t_running
,,t_running=0
,,KillTimer hDlg 1
,,s="Start"; s.setwintext(id(3 hDlg))
,,EnableWindow id(4 hDlg) 0
,
,case 5 ;;Reset
,if(t_running) but 4 hDlg
,t_results=""
,s.setwintext(id(6 hDlg))
,s.setwintext(id(7 hDlg))
ret 1
#3
How to format like this?

http://stopwatch.onlineclock.net/
#4
updated
#5
perfect! thank you
#6
Why does it keep updating to lap 1?

Function dialog_stop_watch
Trigger F7     Help - how to add the trigger to the macro
Code:
Copy      Help
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "7"
str e7
if(!ShowDialog("dialog_stop_watch" &dialog_stop_watch &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 164 178 "Stop Watch"
;3 Button 0x54032000 0x0 4 6 48 14 "Start"
;4 Button 0x5C032000 0x0 58 6 48 14 "Stop"
;5 Button 0x54032000 0x0 110 6 48 14 "Reset"
;6 Static 0x54000000 0x0 56 26 68 12 ""
;7 Edit 0x54230844 0x20000 6 44 152 110 ""
;8 Button 0x54032000 0x0 30 160 48 14 "Save Times"
;9 Button 0x54032000 0x0 86 160 48 14 "Load Times"
;END DIALOG
;DIALOG EDITOR: "" 0x2030208 "*" "" ""

ret
;messages
int-- t_running t_startTime
str s finals
str-- t_results
sel message
,case WM_INITDIALOG
,int lapcount
,case WM_TIMER
,sel wParam
,,case 1
,,s=TimeSpanToStr(timeGetTime-t_startTime*10000 2)
,,s.setwintext(id(6 hDlg))
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3 ;;Start/Lap
,if !t_running ;;start
,,t_running=1
,,t_startTime=timeGetTime
,,SetTimer hDlg 1 100 0
,,EnableWindow id(4 hDlg) 1
,,s="Lap"; s.setwintext(lParam)
,else ;;lap
,,s=TimeSpanToStr(timeGetTime-t_startTime*10000 2)
,,lapcount+1
,,_i=lapcount
,,finals.from("Lap " _i ": " s)
,,t_results.addline(finals 1); t_results.setwintext(id(7 hDlg)); SendMessage id(7 hDlg) WM_VSCROLL SB_BOTTOM 0
,,t_startTime=timeGetTime
,,
,
,case 4 ;;Stop
,if t_running
,,t_running=0
,,KillTimer hDlg 1
,,s="Start"; s.setwintext(id(3 hDlg))
,,EnableWindow id(4 hDlg) 0
,
,case 5 ;;Reset
,if(t_running) but 4 hDlg
,t_results=""
,s.setwintext(id(6 hDlg))
,s.setwintext(id(7 hDlg))
ret 1
#7
lapcount is local variable. Should be int-- lapcount.
#8
duh :lol: thanks gint!
#9
bug: 10000 must be 10000L
Or use perf. I updated the code.
#10
good catch!
greatly appreciated gint!
take care
#11
Hi Gintaras,
I am trying to extract elements of the dlg
Quote:dialog_stop_watch
for a dialog I am working on. I need to pause and unpause various timers. But even a pause/unpause of the single timer seems in this dialog seems to reset back to zero. For example, when you hit stop in this timer dialog, then hit Start again, it starts it back from zero rather than from where it left off.

I think there has to be some subtraction of the most recent "stoptime" in the WM_TIMER
Code:
Copy      Help
s=TimeSpanToStr(timeGetTime-t_startTime*10000 2)
step but I'm having trouble getting it to work. I think I don't know how to convert the time format (msec?) from the last Stopped time and put it into a time format that timeGetTime and t_startTime are in.

Am I getting close?

Stuart
#12
Function dialog_stop_watch
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "7 8"
str e7 c8Pau
if(!ShowDialog("dialog_stop_watch" &dialog_stop_watch &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Button 0x54032000 0x0 4 4 48 14 "Start"
;4 Button 0x5C032000 0x0 4 22 48 14 "Stop"
;5 Button 0x54032000 0x0 4 40 48 14 "Reset"
;6 Static 0x54000000 0x0 58 6 68 12 ""
;7 Edit 0x54230844 0x20000 56 22 70 60 ""
;8 Button 0x54012003 0x0 4 68 48 13 "Pause"
;END DIALOG
;DIALOG EDITOR: "" 0x2030301 "*" "" ""

ret
;messages
int-- t_running t_pause
long-- t_startTime t_activeTime
str s
str-- t_results
sel message
,case WM_INITDIALOG
,
,case WM_TIMER
,sel wParam
,,case 1
,,s=TimeSpanToStr(perf-t_startTime+t_activeTime*10 2)
,,s.setwintext(id(6 hDlg))
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3 ;;Start/Lap
,if !t_running ;;start
,,t_running=1
,,t_startTime=perf
,,SetTimer hDlg 1 100 0
,,EnableWindow id(4 hDlg) 1
,,s="Lap"; s.setwintext(lParam)
,else ;;lap
,,s=TimeSpanToStr(perf-t_startTime+t_activeTime*10 2)
,,t_results.addline(s 1); t_results.setwintext(id(7 hDlg)); SendMessage id(7 hDlg) WM_VSCROLL SB_BOTTOM 0
,,if(t_pause) t_activeTime+perf-t_startTime; else t_activeTime=0
,,t_startTime=perf
,
,case 4 ;;Stop
,if t_running
,,t_running=0
,,if(t_pause) t_activeTime+perf-t_startTime; else t_activeTime=0
,,KillTimer hDlg 1
,,s="Start"; s.setwintext(id(3 hDlg))
,,EnableWindow id(4 hDlg) 0
,
,case 5 ;;Reset
,if(t_running) but 4 hDlg
,t_activeTime=0
,t_results=""
,s.setwintext(id(6 hDlg))
,s.setwintext(id(7 hDlg))
,
,case 8 ;;Pause
,but 5 hDlg
,t_pause=but(lParam)
ret 1

added variable t_activeTime. If Pause checked, adds it to the displayed time.
#13
You're the best! This is a very handy feature!
Thanks, S


Forum Jump:


Users browsing this thread: 1 Guest(s)