|
-
Jul 8th, 2003, 08:19 PM
#1
Thread Starter
Addicted Member
Multiple timers with CreateTimerQueueTimer
I want to execute specific chunks of code at specified intervals. I can do this with ONE chunk of code using the following from API-Guide:
VB Code:
' This project requires a Form and a Module
' The Form must have two command buttons (Command1
' and Command2) on it.
'
'In a form
Private Declare Function CreateTimerQueue Lib "kernel32.dll" () As Long
Private Declare Function CreateTimerQueueTimer Lib "kernel32.dll" (ByRef phNewTimer As Long, ByVal TimerQueue As Long, ByVal Callback As Long, ByVal Parameter As Long, ByVal DueTime As Long, ByVal Period As Long, ByVal Flags As Long) As Long
Private Declare Function DeleteTimerQueue Lib "kernel32.dll" (ByVal TimerQueue As Long) As Long
Private Declare Function DeleteTimerQueueTimer Lib "kernel32.dll" (ByVal TimerQueue As Long, ByVal Timer As Long, ByVal CompletionEvent As Long) As Long
Private hQueue As Long
Private hTimer As Long
Private Sub Form_Load()
'KPD-Team 2002
'URL: [url]http://www.allapi.net/[/url]
hQueue = CreateTimerQueue()
Command1.Caption = "Start"
Command2.Caption = "Stop"
End Sub
Private Sub Form_Unload(Cancel As Integer)
DeleteTimerQueue hQueue
End Sub
Private Sub Command1_Click()
If hTimer = 0 Then
CreateTimerQueueTimer hTimer, hQueue, AddressOf TimerCallBack, ByVal 0&, 0, 1000, 0
End If
End Sub
Private Sub Command2_Click()
If hTimer <> 0 Then
DeleteTimerQueueTimer hQueue, hTimer, ByVal 0&
hTimer = 0
End If
End Sub
'In a module
Public Sub TimerCallBack(ByVal lpParameter As Long, ByVal TimerOrWaitFired As Long)
Debug.Print "Timer callback..."
End Sub
My problem is i can't create more than one timer. Whenever i point CreateTimerQueueTimer to a Sub besides TimerCallBack, an error occurs.
Example: CreateTimerQueueTimer hTimer, hQueue, AddressOf MySub, ByVal 0&, 0, 1000, 0
How can I make that work?
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
|