Results 1 to 5 of 5

Thread: [vb6] - using SetTimer

  1. #1

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

    [vb6] - using SetTimer

    can i use the SetTimer() api function in "shot" way(just 1 time instead a time cyle)?
    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] - using SetTimer

    Yes, very simply. In your timer procedure, simply destroy the timer

    Code:
    Public Sub OneShotTimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal TimerID As Long, ByVal Tick As Long)
        KillTimer hWnd, TimerID
    End Sub
    
    ' sample call
    SetTimer Me.hWnd, [yourID], 10, AddressOf OneShotTimerProc
    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,964

    Re: [vb6] - using SetTimer

    Quote Originally Posted by LaVolpe View Post
    Yes, very simply. In your timer procedure, simply destroy the timer

    Code:
    Public Sub OneShotTimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal TimerID As Long, ByVal Tick As Long)
        KillTimer hWnd, TimerID
    End Sub
    
    ' sample call
    SetTimer Me.hWnd, [yourID], 10, AddressOf OneShotTimerProc
    see the code:
    Code:
    Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Sub Sleep Lib "kernel32.dll" ( _
         ByVal dwMilliseconds As Long)
    Private lTimerId As Long
    
    Public Sub CreateThread(vNewValue As Long)
        lTimerId = SetTimer(UserControl.hWnd, 100&, ByVal 5000, ByVal vNewValue)   
    End Sub
    
    Public Sub DestroyThread()
        If lTimerId Then
            lTimerId = KillTimer(UserControl.hWnd, lTimerId)
            lTimerId = 0
        End If
    End Sub
    (thes is a control that simulates the multithread and works fine)
    like you see i don't have access direct to sub(in control). but thanks for the information. i can put a boolean variable inside the sub(in module) for works 1 time.
    these is the only problem these control have
    what you think about these control?
    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] - using SetTimer

    The vNewValue you are setting the timer's callback procedure to, you do have access to that, correct?

    If so, it should be a standard timer callback sub like the OneShotTimerProc in previous reply. Kill the timer there, once it fires

    I don't think I fully understand the scenario
    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,964

    Re: [vb6] - using SetTimer

    Quote Originally Posted by LaVolpe View Post
    The vNewValue you are setting the timer's callback procedure to, you do have access to that, correct?

    If so, it should be a standard timer callback sub like the OneShotTimerProc in previous reply. Kill the timer there, once it fires

    I don't think I fully understand the scenario
    better is show you: http://www.mediafire.com/?4mmfvqmmhfh2gv0
    (i don't have atachment space)
    in a module i have the procedure: here i must use the variable boolean for don't use, again the sub.
    in form i have 1 controls(for 2 threads(number of thread must be = controls)).
    and heres how use it:
    Code:
    Private Sub Command1_Click()
        MultiThread2.CreateThread AddressOf sub1
        MultiThread1.CreateThread AddressOf sub2
    End Sub
    
    Private Sub Command3_Click()
        MultiThread2.DestroyThread
        MultiThread1.DestroyThread
    End Sub
    thanks
    Last edited by joaquim; Nov 9th, 2011 at 01:13 PM.
    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