• Welcome to Valhalla Legends Archive.
 

Timer

Started by Networks, August 28, 2004, 01:40 PM

Previous topic - Next topic

Networks

Can anyone provide some example code of how to create a timer (not the control)? And some explaination of key statements and how they are used.
Thank you in advance.

Flame


Declare Function SetTimer Lib "user32.dll" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32.dll" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long

-hWnd = Window handle to use.
-nIDEvent = Event index.  Basically if you want to set multiple timers, you're going to want to use different IDEvent numbers, if you want to kill a timer, you need to use the IDEvent in which it was originally set with.
-uElapse = Time elapsed in MS.
-lpTimerFunc = Address of the routine to call once the timer has expired.

Public Sub Main()
    SetTimer frmMain.hWnd, 1, 100, AddressOf MySub
End Sub

Public Sub MySub
    Debug.Print "Hi!"
    KillTimer frmMain.hWnd, 1
End Sub


An additional note, you can also use SetTimer to change the interval on an existing timer.

Eli_1

I may be wrong, but don't you need to use a timerproc as your callback function?



Public Sub MySub(ByVal hWnd as Long, ByVal uMsg as Long, ByVal idEvent as Long, ByVal dwTime as Long)

Select Case idEvent
Case MYTIMER_ONE: DoStuff1()
Case MYTIMER_TWO: DoStuff2()
Case MYTIMER_THREE: DoStuff3()
End Select

End Sub


Networks

yea.. I figured it out after the post but thank you guys anyway.