Private Type POINTAPI
x As Long
y As Long
End Type
Private Type MSG
hWnd As Long 'the window handle of the app
message As Long 'the type of message (e.g. keydown)
wParam As Long 'the key code
lParam As Long 'not used
time As Long 'time when message posted
pt As POINTAPI 'coordinate of mouse pointer
End Type
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" _
(lpMsg As MSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, _
ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function TranslateMessage Lib "user32" _
(lpMsg As MSG) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" _
(lpMsg As MSG) As Long
Private Const PM_REMOVE = &H1
'The alternative function for DoEvents:
Public Sub MyDoEvents()
Dim CurrMsg As MSG
'The following loop extract all messages from the queue and dispatch them
'to the appropriate window.
Do Until PeekMessage(CurrMsg, 0, 0, 0, PM_REMOVE) = 0
TranslateMessage CurrMsg
DispatchMessage CurrMsg
Loop
End Sub