Results 1 to 7 of 7

Thread: SetTimer/KillTimer?

  1. #1

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Hi!

    I'd just like to know what SetTimer and KillTimer (and any other related API) are for, and how to use them? My guess is that SetTimer calls a sub after a certain ammount of time, and KillTimer stops it. Is this true?

    Bye,

    -Jotaf98

    [email protected] - ICQ#60784495 - http://jotaf98.cjb.net

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yes. The Platform SDK has more info, but you set the timer and pass the handle to your form's window, and either subclass and catch WM_TIMER, or use a callback function.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Sorry, but I'm just a newbie... can you please explain a bit better?

    Thanks!

    Bye

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Okay...

    SetTimer sets the timer, when you pass a timer ID, an interval, a window to receive the message, and a callback function. Use the message or callback depending on needs. It returns a handle to the timer that was actually allocated.

    The timer is then used...

    KillTimer just stops and destroys the timer created.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    New Member
    Join Date
    Aug 2000
    Location
    INDIA
    Posts
    7

    Arrow set timer /kill timmer

    hi,

    SetTimer creates a timer that triggers an event after so many milliseconds have elapsed. The timer continues triggering events between intervals until it is removed using KillTimer. The timer can be configured to either send a WM_TIMER message to the owning window or call a callback function whenever

    Kill Timer is used to destroy the timer which is getting executed again and again with elapsed time.





  6. #6
    Guest
    I'm suprised no one posted an example already. Anyhow, try this. Put the follwoing in a Module
    Code:
    Declare Function SetTimer Lib "user32" (ByVal HWND As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Declare Function KillTimer Lib "user32" (ByVal HWND As Long, ByVal nIDEvent As Long) As Long
    
    Function TimerProc(HWND As Long, uMsg As Long, EventID As Long, dwTime As Long) As Long
        'This MessageBox will display every second
        msg = MsgBox("This will display every second until you press no", vbYesNo)
        'If "No" is pressed then destroy the Timer
        If msg = vbNo Then
            Call KillTimer(Form1.HWND, 1000)
        End If
    End Function
    Put the following into a Form with a CommandButton
    Code:
    Private Sub Command1_Click()
        'The Timer will begin when this button is clicked
        Call SetTimer(Me.HWND, 1000, 1000, AddressOf TimerProc)
    End Sub

  7. #7

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    This is soooooo cool!

    It makes life a lot easier in more things that I can remember right now, mostly in my game

    Thanks everyone!

    Bye

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