|
-
Aug 18th, 2000, 06:42 PM
#1
Thread Starter
Frenzied Member
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
-
Aug 19th, 2000, 06:52 AM
#2
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 21st, 2000, 05:42 PM
#3
Thread Starter
Frenzied Member
Sorry, but I'm just a newbie... can you please explain a bit better?
Thanks!
Bye
-
Aug 21st, 2000, 06:39 PM
#4
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 23rd, 2000, 06:21 AM
#5
New Member
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.
-
Aug 23rd, 2000, 09:01 AM
#6
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
-
Aug 23rd, 2000, 06:35 PM
#7
Thread Starter
Frenzied Member
This is soooooo cool!
It makes life a lot easier in more things that I can remember right now, mostly in my game 
Thanks everyone!
Bye
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|