-
Hi!
I'd just like to know what SetTimer and KillTimer (and any other related API) are for, and how to use them? My guess is that SetTimer calls a sub after a certain ammount of time, and KillTimer stops it. Is this true?
Bye,
-Jotaf98
[email protected] - ICQ#60784495 - http://jotaf98.cjb.net
-
Yes. The Platform SDK has more info, but you set the timer and pass the handle to your form's window, and either subclass and catch WM_TIMER, or use a callback function.
-
Sorry, but I'm just a newbie... can you please explain a bit better?
Thanks!
Bye
-
Okay...
SetTimer sets the timer, when you pass a timer ID, an interval, a window to receive the message, and a callback function. Use the message or callback depending on needs. It returns a handle to the timer that was actually allocated.
The timer is then used...
KillTimer just stops and destroys the timer created.
-
set timer /kill timmer
hi,
SetTimer creates a timer that triggers an event after so many milliseconds have elapsed. The timer continues triggering events between intervals until it is removed using KillTimer. The timer can be configured to either send a WM_TIMER message to the owning window or call a callback function whenever
Kill Timer is used to destroy the timer which is getting executed again and again with elapsed time.
-
I'm suprised no one posted an example already. Anyhow, try this. Put the follwoing in a Module
Code:
Declare Function SetTimer Lib "user32" (ByVal HWND As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal HWND As Long, ByVal nIDEvent As Long) As Long
Function TimerProc(HWND As Long, uMsg As Long, EventID As Long, dwTime As Long) As Long
'This MessageBox will display every second
msg = MsgBox("This will display every second until you press no", vbYesNo)
'If "No" is pressed then destroy the Timer
If msg = vbNo Then
Call KillTimer(Form1.HWND, 1000)
End If
End Function
Put the following into a Form with a CommandButton
Code:
Private Sub Command1_Click()
'The Timer will begin when this button is clicked
Call SetTimer(Me.HWND, 1000, 1000, AddressOf TimerProc)
End Sub
-
This is soooooo cool!
It makes life a lot easier in more things that I can remember right now, mostly in my game :p
Thanks everyone!
Bye