home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "modTimer"
- Option Explicit
-
- Declare Function SetTimer Lib "user32" _
- (ByVal hwnd As Long, ByVal nIDEvent As Long, _
- ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
- Attribute SetTimer.VB_MemberFlags = "40"
- Declare Function KillTimer Lib "user32" _
- (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
- Attribute KillTimer.VB_MemberFlags = "40"
-
- ' This collection holds pointers to all of the CTimer objects
- ' that have active Window's timers. The key is the timerID belonging
- ' to the timer associated with the object.
- Private cTimers As Collection
-
- ' This callback is shared among the different timers and can be
- ' distinguished from each other by the timer ID pass in. Its string
- ' representation is used as the key to get the associated CTimer object.
- Public Sub TimerProc(ByVal hwnd As Long, ByVal msg As Long, _
- ByVal idEvent As Long, ByVal curTime As Long)
- Dim tim As CTimer
-
- ' Find the timer that fired in the CTimers collection
- Set tim = cTimers.Item(Str$(idEvent))
-
- If Not tim Is Nothing Then
- ' Once the appropriate CTimer is found, call its Timer_Event function
- ' so that it can raise the event to its clients.
- tim.Timer_Event
- Else
- Debug.Print "Timer " & idEvent & " not found in collection."
- End If
- End Sub
-
- Public Sub Main()
- ' Create the timers collection object.
- Set cTimers = New Collection
- End Sub
-
- Public Sub AddTimer(objTimer As CTimer)
- Attribute AddTimer.VB_MemberFlags = "40"
- ' Add CTimer object to collection. Use the object's TimerID
- ' as the search key (note that the key is of type String)
- cTimers.Add Item:=objTimer, Key:=objTimer.TimerID
- End Sub
-
- Public Sub RemoveTimer(objTimer As CTimer)
- Attribute RemoveTimer.VB_MemberFlags = "40"
- ' The Window's timer associated with the CTimer object has been killed.
- ' Using the object's timer ID as the key, remove the CTimer object
- ' from the cTimers collection.
- cTimers.Remove objTimer.TimerID
- End Sub
-