I think the code I came up with works well and does not have a disruptive effect.
I have also not seen a high CPU load.
I need the code for a game, the timing is pretty tight so that a good interaction takes place.
Sub MsgWait(ByVal MilliSeconds as DWORD)
Dim start as DWORD, timeRemaining as DWORD, timeNow as DWORD
Dim uMsg as Msg
start = GetTickCount()
timeRemaining = MilliSeconds
Do
If PeekMessage(VarPtr(uMsg), 0, 0, 0, PM_REMOVE) <> 0 Then
If IsDialogMessage(GetActiveWindow, VarPtr(uMsg)) = 0 Then
TranslateMessage VarPtr(uMsg)
DispatchMessage VarPtr(uMsg)
End If
End If
timeNow = GetTickCount()
If timeNow - start >= timeRemaining Then
Exit Sub
ElseIf timeNow < start Then
' Handle GetTickCount 49.7 day wrap around
start = timeNow
End If
timeRemaining = timeRemaining - (timeNow - start)
start = timeNow
Loop
End Sub