Results 1 to 12 of 12

Thread: [RESOLVED] [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Resolved [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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    Quote Originally Posted by LaVolpe View Post
    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
    but can you tell me why that code closes the vb6?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    Quote Originally Posted by joaquim View Post
    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    Quote Originally Posted by LaVolpe View Post
    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    Quote Originally Posted by LaVolpe View Post
    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    for finish: how can i test 1 second?
    100 milliseconds = 1 second?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    Quote Originally Posted by joaquim View Post
    100 milliseconds = 1 second?
    No, 1000 ms = 1 sec
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    Quote Originally Posted by LaVolpe View Post
    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    Quote Originally Posted by joaquim View Post
    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,966

    Re: [VB6] - Multimedia timers(timeSetEvent() and timeKillEvent() api functions)

    Quote Originally Posted by LaVolpe View Post
    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width