CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: VB timer query

  1. #1
    Join Date
    Mar 2006
    Posts
    41

    Thumbs up VB timer query

    Hi Gurus!

    I have created one form which contains timer.When i holding click on any of the titlebar icon(i.e. close,minimize,maximize) the timer gets paused. After releasing the click on icons, the timer gets start.



    Waiting for your helpful solutions.

    Thanx.
    Last edited by ashik143; July 25th, 2007 at 06:35 AM.

  2. #2
    Join Date
    Mar 2002
    Location
    Croatia
    Posts
    275

    Re: VB timer query

    If I understand your problem, you want a timer alway running, not paused by mouse actions.

    Add another form to your project and make it invisible. Put a timer to this invisible form, so it will not receive mouse events

    I didn't try it, it's just a suggestion. I think it may work.

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: VB timer query

    You could use the Timer-API. Put this code 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
    
    Public TimerHandle As Long
    
    Public Sub TimerProc(hwnd As Long, msg As Long, idTimer As Long, dwTime As Long)
      
    ' This procedure is called repeatedly. You can do everything like in the timer event.
      Beep
    End Sub
    
    Public Sub StartTimer(Interval As Long)
    ' create timer with given interval
    ' the timer is given the address of the procedure to execute in intervals
      TimerHandle = SetTimer(0, 0, Interval, AddressOf TimerProc)
    End Sub
    
    Public Sub StopTimer()
    ' stop and destroy the timer
      KillTimer 0, TimerHandle
      TimerHandle = 0
    End Sub
    I think the interval is specified in microseconds.
    A call to StartTimer() creates an API-timer and calls your TimerProc() in a specified interval.
    To stop, you call StopTimer()
    It's a timer the OS handles and I think it is not stopped by mouse events.

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

Featured