-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimer.cls
More file actions
106 lines (106 loc) · 3.01 KB
/
Copy pathTimer.cls
File metadata and controls
106 lines (106 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Timer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Const DEBUGMODE As Boolean = False
Private Declare Function apiSetTimer Lib "user32" Alias "SetTimer" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function apiKillTimer Lib "user32" Alias "KillTimer" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private timerId As Long
Private isActive As Boolean
Public Interval As Long
Public Tag As Variant
Public Event Timer()
'Public Event Elapsed()
Private mvarIndex As Long
Private mvarParentKeyClass As Variant
Private Sub Class_Initialize()
Interval = 2000
End Sub
Private Sub Class_Terminate()
TimerDestroy
End Sub
Friend Property Let Index(dwIndex As Long)
mvarIndex = dwIndex
End Property
Friend Property Get Index() As Long
Index = mvarIndex
End Property
Friend Property Let ParentKeyClass(key As Long)
mvarParentKeyClass = key
End Property
Friend Property Get ParentKeyClass() As Long
ParentKeyClass = mvarParentKeyClass
End Property
Property Get Enabled() As Boolean
Enabled = isActive
End Property
Property Let Enabled(ByRef activate As Boolean)
If activate = True And isActive = True Then
Reset
ElseIf activate = True And Not isActive = True Then
Enable
ElseIf isActive = True And Not activate = True Then
Disable
ElseIf Not isActive = True And Not activate = True Then
End If
End Property
Sub EnableTimer(mInterval As Long)
If Interval = mInterval And isActive = True Then TimerDestroy
Interval = mInterval
Enable
End Sub
Sub Enable()
If isActive = True Then TimerDestroy
TimerCreate
End Sub
Sub Disable()
TimerDestroy
End Sub
Sub Reset()
TimerDestroy
TimerCreate
End Sub
Public Sub RaiseTimer_Event()
RaiseEvent Timer
' RaiseEvent Elapsed
End Sub
Private Function TimerCreate() As Boolean
If Interval <= 0 Then Exit Function
timerId = apiSetTimer(0, 0, Interval, AddressOf TimerProc)
If timerId <> 0 Then
TimerCreate = True
Timercollection.Add Me, "id:" & timerId
isActive = True
Else
timerId = 0
TimerCreate = False
isActive = False
End If
End Function
Private Function TimerDestroy() As Long
Dim i As Integer
Dim f As Boolean
If TimerExists() = True Then
f = apiKillTimer(0, timerId)
Timercollection.Remove "id:" & timerId
TimerDestroy = True
isActive = False
End If
End Function
Private Function TimerExists() As Boolean
On Error Resume Next: Err.Clear
Dim c As Timer
Set c = Timercollection("id:" & timerId)
If Err.Number = 0 Then TimerExists = True
Set c = Nothing
End Function