[INCLUDE]
DoEventsEx_Sleep

[DEFINE]
Private Const SleepValueHigh As Long = 100&
'see also consts in DoEventsEx

[CODE]
Public Sub DoEventsEx(ByVal TimeIntervalMs As Long, Optional ByVal FirstTickValue As Long = -1&)
  Static xLong1 As Long

  If TimeIntervalMs > SleepValueHigh Or FirstTickValue = -1& Then
    If FirstTickValue = -1& Then
      FirstTickValue = GetTickCount And &H3FFFFFFF
      End If
    DoEventsEx_Sleep SleepValueHigh
    Do
      xLong1 = GetTickCount And &H3FFFFFFF
      If xLong1 < FirstTickValue Then
        xLong1 = TimeIntervalMs - (xLong1 + &H40000000 - FirstTickValue)
        Else
        xLong1 = TimeIntervalMs - (xLong1 - FirstTickValue)
        End If
      If xLong1 > 0& Then
        If xLong1 > SleepValueHigh Then xLong1 = SleepValueHigh
        DoEventsEx_Sleep xLong1
        Else
        Exit Do
        End If
      Loop
    Else
    DoEventsEx_Sleep TimeIntervalMs
    End If
  End Sub
