Hi. Somebody in this NG gave me the adress which I can't
remember right now, but here's what I found there:
Using a Timer Without a Form {28-May-1999}
The Timer control in VB must be situated on a form in order to be part
of
the project. In some cases, notably ActiveX servers, there may not be
any form to act as a host. Although in many cases a form can be loaded
and simply not shown, it is also possible to use a system timer via
API
calls without using a control.
Start a new project and place the following code in a module:
Option Explicit
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, _
ByVal nIDEvent As Long) As Long
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 GetDesktopWindow Lib "user32" () As Long
Public Function TimerEnable(ByVal hWnd As Long, _
ByVal TimerID As Long, ByVal mSecs As Long) As Long
TimerEnable = SetTimer(hWnd, TimerID, mSecs, _
AddressOf TimerFired)
End Function
Public Function TimerDisable(ByVal hWnd As Long, _
ByVal TimerID As Long) As Long
TimerDisable = KillTimer(hWnd, TimerID)
End Function
Private Sub TimerFired(ByVal hWnd As Long, _
ByVal TimerID As Long, ByVal IDEvent As Long, _
ByVal dwTime As Long)
Debug.Print "Fired "; hWnd; TimerID; IDEvent; dwTime
End Sub
Then place this code in a form (just for testing) after creating two
command buttons named cmdStart and cmdStop:
Option Explicit
Private mlTimer1 As Long
Private mlTimer2 As Long
Private Sub cmdStart_Click()
mlTimer1 = TimerEnable(0, 1, 3000)
mlTimer2 = TimerEnable(0, 2, 5000)
Debug.Print "Start 1: "; mlTimer1
Debug.Print "Start 2: "; mlTimer2
End Sub
Private Sub cmdStop_Click()
Debug.Print "Stop: "; TimerDisable(0, mlTimer1)
Debug.Print "Stop: "; TimerDisable(0, mlTimer2)
End Sub
When you run the application you should be able to click the START
button
and watch the timer events occurring in the debug window. Clicking
STOP
will terminate the timers. There are a few things to watch out for:
1. ALWAYS be sure to stop the timers before stopping the program. If
you
don't then the timers will continue to run and your app may appear in
the
tasklist after terminating.
2. The return value from the SetTimer call will be the IDEvent value
in
the function run when it fires. You can test this value to determine
which timer fired if more than one is started.
3. The function MUST be in a BAS module in VB5 due to restrictions in
the
AddressOf operator. If you need to reference it in multiple class or
other
modules then your function must know how to re-direct the event to the
appropriate place. An alternative is using a different function for
each
SetTimer call.
On Sun, 18 Jul 1999 19:55:41 -0500, "Harvey Triana"
Quote:
>- Yes
>Search in VB samples, XTimer.
>________________________________________________
>Harvey Triana
>Visual Basic Developer MVP
> http://www.*-*-*.com/
>________________________________________________
>is it a way to programatically create a Timer object except by embedding it
>on a form?
> if not, are there any controls that behave like a Timer object but can be
>created with
>the "new" syntax?
> help appreciated.
Best regards,
Zeljko
We are born {*filter*}, wet, and hungry.
Then things got worse.