Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SetTimer Lib "user32" (ByVal HWnd As LongPtr, ByVal nIDEvent As LongPtr, _
ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Private Declare PtrSafe Function KillTimer Lib "user32" (ByVal HWnd As LongPtr, _
ByVal nIDEvent As LongPtr) As LongPtr
#Else
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
#End If
Private TimerID
Private m_Interval As Long
Public Property Let Interval(ByVal Value As Long)
If CBool(Value) Then
StartTimer Value
Else
StopTimer
End If
End Property
Private Sub StartTimer(ByVal Interval As Long)
If Interval <= 0 Then Exit Sub ' Vérifier si l'intervalle est valide
m_Interval = Interval
' Créer un timer avec l'intervalle spécifié
TimerID = SetTimer(0, 0, m_Interval, AddressOf TimerProc)
End Sub
Private Sub StopTimer()
' Arrêter le timer
KillTimer 0, TimerID
m_Interval = 0
End Sub
Private Sub Class_Terminate()
StopTimer
End Sub