Click to See Complete Forum and Search --> : SetTimer/KillTimer?
Jotaf98
Aug 18th, 2000, 06:42 PM
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
jotaf98@hotmail.com - ICQ#60784495 - http://jotaf98.cjb.net
parksie
Aug 19th, 2000, 06:52 AM
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.
Jotaf98
Aug 21st, 2000, 05:42 PM
Sorry, but I'm just a newbie... can you please explain a bit better?
Thanks!
Bye
parksie
Aug 21st, 2000, 06:39 PM
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.
diwakar
Aug 23rd, 2000, 06:21 AM
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
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
Private Sub Command1_Click()
'The Timer will begin when this button is clicked
Call SetTimer(Me.HWND, 1000, 1000, AddressOf TimerProc)
End Sub
Jotaf98
Aug 23rd, 2000, 06:35 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.