This forum has more on the topic.
http://www.vbforums.com/showthread.php?t=344709
And it has an interesting API call where you check the status to see if there are items waiting in the Queue
Option Explicit Private Const QS_HOTKEY = &H80 Private Const QS_KEY = &H1 Private Const QS_MOUSEBUTTON = &H4 Private Const QS_MOUSEMOVE = &H2 Private Const QS_PAINT = &H20 Private Const QS_POSTMESSAGE = &H8 Private Const QS_SENDMESSAGE = &H40 Private Const QS_TIMER = &H10 Private Const QS_ALLINPUT = (QS_SENDMESSAGE Or QS_PAINT Or QS_TIMER Or QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or QS_KEY) Private Declare Function GetQueueStatus Lib "user32" (ByVal fuFlags As Long) As Long Private Sub Form_Click() Dim lngDoEventCnt As Long Dim lngLoopCount As Long Do If GetQueueStatus(QS_ALLINPUT) <> 0 Then lngDoEventCnt = lngDoEventCnt + 1 DoEvents End If lngLoopCount = lngLoopCount + 1 Loop Until lngLoopCount = 2000000 Debug.Print lngDoEventCnt End Sub
Another post from the forum is below:
HOWTO: Determine the Differences Between DoEvents and Sleep
Q158175
SUMMARY
This article explains the differences between the Visual Basic DoEvents function and
the Sleep() Windows API function.
MORE INFORMATION
DoEvents is a Visual Basic function that yields execution so the operating system can
process other events. This function cleans out the message loop and executes any other
pending business in the Visual Basic runtime. Upon completing the pending business
execution, the function calls the Sleep function with zero (0) as the argument so that
the remaining time slice can be used to check the queue.
The Sleep 32-bit API function is a subset of the DoEvents function. The Visual Basic
program calling the function and the Visual Basic runtime executable and interactions
with Windows are immediately put to sleep by this function. The programs remain inactive
for the time in milliseconds specified in the Sleep argument.
The Sleep function allows you to specify the amount of time your applications are
inactive. The DoEvents function returns control to the Visual Basic program after
the operating system has finished processing the events in its queue and all keys in
the SendKeys queue have been sent.
The information in this article applies to:
Microsoft Visual Basic Learning Edition for Windows 5.0
Microsoft Visual Basic Learning Edition for Windows 6.0
Microsoft Visual Basic Professional Edition for Windows 5.0
Microsoft Visual Basic Professional Edition for Windows 6.0
Microsoft Visual Basic Enterprise Edition for Windows 5.0
Microsoft Visual Basic Enterprise Edition for Windows 6.0
Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
Last Reviewed: 5/13/2003 (3.0)
Keywords: kbhowto KB158175
Q158175
SUMMARY
This article explains the differences between the Visual Basic DoEvents function and
the Sleep() Windows API function.
MORE INFORMATION
DoEvents is a Visual Basic function that yields execution so the operating system can
process other events. This function cleans out the message loop and executes any other
pending business in the Visual Basic runtime. Upon completing the pending business
execution, the function calls the Sleep function with zero (0) as the argument so that
the remaining time slice can be used to check the queue.
The Sleep 32-bit API function is a subset of the DoEvents function. The Visual Basic
program calling the function and the Visual Basic runtime executable and interactions
with Windows are immediately put to sleep by this function. The programs remain inactive
for the time in milliseconds specified in the Sleep argument.
The Sleep function allows you to specify the amount of time your applications are
inactive. The DoEvents function returns control to the Visual Basic program after
the operating system has finished processing the events in its queue and all keys in
the SendKeys queue have been sent.
The information in this article applies to:
Microsoft Visual Basic Learning Edition for Windows 5.0
Microsoft Visual Basic Learning Edition for Windows 6.0
Microsoft Visual Basic Professional Edition for Windows 5.0
Microsoft Visual Basic Professional Edition for Windows 6.0
Microsoft Visual Basic Enterprise Edition for Windows 5.0
Microsoft Visual Basic Enterprise Edition for Windows 6.0
Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
Last Reviewed: 5/13/2003 (3.0)
Keywords: kbhowto KB158175
No comments:
Post a Comment