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
and in a module: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
can anyone explain to me what isn't right?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






Reply With Quote