I threw this together to try and answer a question posted elsewhere.
It show three of many ways to use timers. A one-time timer to keep a splash screen up for three seconds, a timer to count seconds the entire time the main form is shown, and a timer that the user can start and stop, that also counts seconds. It demonstrates that once you start a timer, it will fire the event routine when the timer reaches zero. The timer automatically restarts withe the old interval and will start the countdown again. It will only stop when the timer is killed. While you can kill a timer anytime and anywhere in your program, the timer event is a good place to kill the timer or to change the interval (as well as anything you wanted to process at the end of the interval).
Hope it is of use to some of you.
David
Nice, David. Thanks for posting.
Global gUCTSeconds As Long
'--------------------------------------------------------------------------------
Function MAINFORM_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ ' optional user defined Long value
) As Long
SetTimer(hWndForm, IDC_MainForm_SplashScreenTmr, 3000) 'Set timer for three seconds
SplashScreen_Show(hWndForm, %True)
End Function
'--------------------------------------------------------------------------------
Function MAINFORM_SPLASHSCREENTMR_WM_TIMER ( _
hWndForm As Dword, _ ' handle of Form
wTimerID As Dword _ ' the timer identifier
) As Long
KillTimer(hWndForm,wTimerID) 'This makes sure the SplashScreen timer only happens once
FF_CloseForm( HWND_SplashScreen )
SetTimer( hWndForm, IDC_MainForm_SecondsTmr,1000 ) 'Set the Seconds timer for 1 second intervals.
End Function
'--------------------------------------------------------------------------------
Function MAINFORM_SECONDSTMR_WM_TIMER ( _
hWndForm As Dword, _ ' handle of Form
wTimerID As Dword _ ' the timer identifier
) As Long
'We don't kill this one.... it counts down forever.
Static Seconds As Long
Incr Seconds
FF_Control_SetText( HWND_MainForm_SecondsLbl, "Form active for" & Str$(Seconds) & " seconds." )
End Function
'--------------------------------------------------------------------------------
Function MAINFORM_STARTBTN_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
gUCTSeconds = 0
FF_Control_SetText( HWND_MainForm_UserControlledLbl, "" )
SetTimer (hWndForm,IDC_MainForm_UserControlledTmr, 1000) 'Set the timer to 1 full second again
End Function
'--------------------------------------------------------------------------------
Function MAINFORM_STOPBTN_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
KillTimer(hWndForm,IDC_MainForm_UserControlledTmr)
FF_Control_SetText( HWND_MainForm_UserControlledLbl, "User controlled timer killed after" & Str$(gUCTSeconds) & " seconds." )
End Function
'--------------------------------------------------------------------------------
Function MAINFORM_USERCONTROLLEDTMR_WM_TIMER ( _
hWndForm As Dword, _ ' handle of Form
wTimerID As Dword _ ' the timer identifier
) As Long
'This timer interval is set to 1000 milliseconds(1 second) at design time in the timer properties.
'It can be stopped and started by the user. The counter is reset when the user selects the Start button.
Incr gUCTSeconds
FF_Control_SetText( HWND_MainForm_UserControlledLbl, "User controlled timer active for" & Str$(gUCTSeconds) & " seconds." )
End Function
Hello Theo,
I am not sure what you are trying to show here?