This example shows how two timers can be handleed within 'WndProc'.

All messages sent to the UserForm's window pass through WndProc. The WM_TIMER messages are taken care of by our WndProc; all other messages are passed on to the original WndProc to be handled there.

This is how WndProc looks:


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


Go to top