Das Beispiel zeigt wie zwei Timer mit unterschiedlichen Zeitintervallen behandelt werden können.
Alle an das Userform-Fenster gerichteten Messages laufen durch die WndProc. Die WM_TIMER-Messages werden ausgefiltert und abgehandelt; alle anderen Messages werden an die ursprüngliche WndProc zur Verarbeitung weitergeleitet.
Die WndProc sieht so aus:
Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim st As SYSTEMTIME
Static lsecs As Long
Select Case uMsg
Case WM_TIMER
Select Case wParam
Case ID_TIMER1 'display time
lsecs = lsecs + 1 'inc. loop counter
GetLocalTime st
frmSB_Demo.SetSBText Format$(st.wHour & st.wMinute & st.wSecond, "00:00:00"), 2
Case ID_TIMER2
frmSB_Demo.SetSBText "Looping through delay counter: " _
& Format$(iTimeInterval - lsecs, "000") & " secs left", 0
If lsecs > iTimeInterval Then 'when time is up
frmSB_Demo.SetSBText "Another proc started", 0 'do something
End If
End Select
Case Else
' Here, we forward all irrelevant messages on to the default message handler.
WndProc = CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam)
End Select
End Function