[RESOLVED] [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
i'm trying build a timer with timeSetEvent() and timeKillEvent() api functions(multimedia timer), but my vb6 gives a windows error and then close it:(
Code:
Public Property Let Enabled(ByVal vNewValue As Boolean)
If lngInterval < 1 Then Exit Property
blnTimer = vNewValue
If Ambient.UserMode = False Then Exit Property
If blnTimer = True Then
If lTimerId Then
'End Current Timer
If lTimerId Then
'lTimerId = KillTimer(UserControl.hWnd, lTimerId)
timeKillEvent lTimerId
lTimerId = 0
End If
End If
'lTimerId = SetTimer(UserControl.hWnd, 100&, ByVal Interval, AddressOf TimerRoutine) 'the problem is these line
lTimerId = timeSetEvent(lngInterval, 0, AddressOf TimerRoutine, 0, TIME_CALLBACK_FUNCTION Or TIME_PERIODIC)
ElseIf blnTimer = False Then
If lTimerId Then
'lTimerId = KillTimer(UserControl.hWnd, lTimerId)
timeKillEvent lTimerId
lTimerId = 0
End If
End If
PropertyChanged "Enabled"
End Property
and in a module:
Code:
Option Explicit
Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uId As Long) As Long
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Public Const TIME_PERIODIC = 1 ' program for continuous periodic event
Public Const TIME_CALLBACK_FUNCTION = 0
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_KEYDOWN = &H100
Public Sub TimerRoutine(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lIDEvent As Long, ByVal lTime As Long)
'Place your code here...
SendMessage lHwnd, WM_KEYDOWN, 1000, 0
End Sub
can anyone explain to me what isn't right?
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Years ago when I first wanted to learn more about multimedia timers, I found this article on vbAccelerator. It is pretty thorough. Notice what that article says about which messages are allowed in the callback routine. Also note that timeSetEvent is obsolete per MSDN
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Quote:
Originally Posted by
LaVolpe
but can you tell me why that code closes the vb6?
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Quote:
Originally Posted by
joaquim
but can you tell me why that code closes the vb6?
Does it crash if you have no code in the callback? If not, read the article. My guess: SendMessage
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Quote:
Originally Posted by
LaVolpe
Does it crash if you have no code in the callback? If not, read the article. My guess: SendMessage
yes... it's, is there another way to avoid that?
the call back function(public, sure) can be do it? don't block with others apitimer controls?
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Per that vbAccelerator article's sample code: Function, not sub
Code:
Public Function TimerRoutine( _
ByVal wTimerID As Long, ByVal iMsg As Long, _
ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long _
) As Long
End Function
Function returns no value. Additionally that multimedia callback has 5 parameters not 4. Strongly recommend you read over that article and download the sample code to review it
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Quote:
Originally Posted by
LaVolpe
Per that vbAccelerator article's sample code: Function, not sub
Code:
Public Function TimerRoutine( _
ByVal wTimerID As Long, ByVal iMsg As Long, _
ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long _
) As Long
End Function
Function returns no value. Additionally that multimedia callback has 5 parameters not 4. Strongly recommend you read over that article and download the sample code to review it
with that advice and 1 public variable i put it to work(for catch the usercontrol.hwnd property and use it in sendmessage() api function).
and seems more acuracy and definition.
thanks very much
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
for finish: how can i test 1 second?
100 milliseconds = 1 second?
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Quote:
Originally Posted by
joaquim
100 milliseconds = 1 second?
No, 1000 ms = 1 sec
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Quote:
Originally Posted by
LaVolpe
No, 1000 ms = 1 sec
some api funcions and vb6 timer control have only 100 and not 1000(tell if i'm incorrect) and the multimedia functions(timeSetEvent() and timeKillEvent() api functions) are 1000.
thanks for the information and the gelp
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Quote:
Originally Posted by
joaquim
some api funcions and vb6 timer control have only 100 and not 1000(tell if i'm incorrect) and the multimedia functions(timeSetEvent() and timeKillEvent() api functions) are 1000.
thanks for the information and the gelp
Not quite. VB's timer is milliseconds also. 1 millisecond is 1/1000th of a second. However, not all intervals are milliseconds. For example, GIFs use 100ths of a second, not 1000ths of second.
Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)
Quote:
Originally Posted by
LaVolpe
Not quite. VB's timer is milliseconds also. 1 millisecond is 1/1000th of a second. However, not all intervals are milliseconds. For example, GIFs use 100ths of a second, not 1000ths of second.
ok.. thanks for the information... thanks