Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timers without a form? 1

Status
Not open for further replies.

mmilan

Programmer
Jan 22, 2002
839
GB
I've written a simple class as a DLL for implementing timer functionality simply and easily. You don't need a form, and it isn't limited to 65 seconds either...

If anyone want's a copy, email me at m dot milan at blueyonder dot co dot uk
 

Why not post the code (or a simple version) so all may enjoy your wisdom in the ages to come?



 
Place this code in a project with a textbox with multiline property ='ing True

[green]'In a module

[/green][blue]Public Declare Function [/blue]SetTimer [blue]Lib [/blue]"user32" ([blue]ByVal [/blue]hWnd [blue]As Long[/blue], [blue]ByVal [/blue]nIDEvent [blue]As Long[/blue], [blue]ByVal [/blue]uElapse [blue]As Long[/blue], ByVal lpTimerFunc [blue]As [/blue]Long) As Long
[blue]Public Declare Function [/blue]KillTimer [blue]Lib [/blue]"user32" ([blue]ByVal [/blue]hWnd [blue]As Long[/blue], ByVal nIDEvent [blue]As Long[/blue]) As Long
[green]'ontop api
[/green][blue]Public Declare Function [/blue]SetWindowPos [blue]Lib [/blue]"user32" ([blue]ByVal [/blue]hWnd [blue]As Long[/blue], ByVal hWndInsertAfter [blue]As Long[/blue], [blue]ByVal [/blue]x [blue]As Long[/blue], y, [blue]ByVal [/blue]cx [blue]As Long[/blue], ByVal cy [blue]As Long[/blue], ByVal wFlags As Long) As Long

[green]'api constants
[/green][blue]Public Const [/blue]HWND_TOPMOST = -1
[blue]Public Const [/blue]HWND_NOTOPMOST = -2
[blue]Public Const [/blue]SWP_NOMOVE = &H2
[blue]Public Const [/blue]SWP_NOSIZE = &H1
[blue]Public Const [/blue]SWP_NOACTIVATE = &H10
[blue]Public Const [/blue]SWP_SHOWWINDOW = &H40
[blue]Public Const [/blue]TOPMOST_FLAGS = SWP_NOMOVE [blue]Or [/blue]SWP_NOSIZE


[blue]Public Sub [/blue]TimerProc([blue]ByVal [/blue]hWnd [blue]As Long[/blue], [blue]ByVal [/blue]nIDEvent [blue]As Long[/blue], [blue]ByVal [/blue]uElapse [blue]As Long[/blue], [blue]ByVal [/blue]lpTimerFunc [blue]As Long[/blue])
[blue]With [/blue]Form1.Text1
.Text = .Text & "Fired" & Now & vbCrLf
[blue]End With
End Sub

[/blue][green]'Form

[/green][blue]Option Explicit

Private Sub [/blue]Form_Load()
[blue]Dim [/blue]a [blue]As Long
[/blue]a = SetTimer(Me.hWnd, 0, 1000, [blue]AddressOf [/blue]TimerProc)
Text1.Text = a
[blue]End Sub

Private Sub [/blue]Form_Unload(Cancel [blue]As Integer[/blue])
[green]'Kill our API-timer
[/green]KillTimer Me.hWnd, 0
[blue]End Sub

[/blue]

:)
 
You dont need the SetWindowPos API or the Const's
 
Very similar to the approach I have taken, but the dll is the result of a combination of a class file and a module. I suppose I could post both and leave you all to try and compile it yourselves, but I'm in the office at the moment, so I'll have to try and remember to do it tonight...

mmilan
 
Yes I have one in a class for a timer array but this is much simpler as an example
 
>I have one in a class

Don't we all? :)

Actually, I'm pretty certain I posted a vbTimer class solution to this forum about 18 months ago - but I can't seem to find it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top