README.md
December 5, 2022 ยท View on GitHub
Description
How to use John Galanopoulos' article in a class module to override the standard DoEvents method.
More Info
| Submitted On | 2002-04-04 09:56:02 |
| By | JohnB |
| Level | Intermediate |
| User Rating | 5.0 (60 globes from 12 users) |
| Compatibility | VB 4.0 (32-bit), VB 5.0, VB 6.0, VBA MS Access, VBA MS Excel |
| Category | Windows API Call/ Explanation |
| World | Visual Basic |
| Archive File | DoEvents_E68736442002.zip |
Source Code
I added/changed some code to further optimize my code which basically is an optimization of the DoEvents method. Thanks goes to Marzo Sette Torres Junior for his help!
It is best to view the article located here: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=29735&lngWId=1
Next download the code attached, which is just a class module. I included the Word DOC file from John G. with the class module.
Simply add the module to your project and declare an object of the clsDoEvents type:
Dim oDoEvents as clsDoEvents
Set oDoEvents = New clsDoEvents
Then set its only property to any of the enumerated values.
oDoEvents.QueueUsed = Standard
Valid enumerated values for this property
All_Inputs = QS_ALLINPUT
All_Events = QS_ALLEVENTS
Standard = QS_STANDARD
Messages = QS_MESSAGES
InputOnly = QS_INPUT
Mouse = QS_MOUSE
MouseMove = QS_MOUSEMOVE
Timer = QS_TIMER
Constants relating to the above enumerated values:
QS_HOTKEY = &H80
QS_KEY = &H1
QS_MOUSEBUTTON = &H4
QS_MOUSEMOVE = &H2
QS_PAINT = &H20
QS_POSTMESSAGE = &H8
QS_SENDMESSAGE = &H40
QS_TIMER = &H10
QS_MOUSE = (QS_MOUSEMOVE Or
QS_MOUSEBUTTON)
QS_INPUT = (QS_MOUSE Or QS_KEY)
QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT Or _
QS_HOTKEY)
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)
QS_MESSAGES = (QS_POSTMESSAGE Or QS_SENDMESSAGE) ' Not MS standard constant
QS_STANDARD = (QS_HOTKEY Or QS_KEY Or QS_MOUSEBUTTON Or QS_PAINT) ' Not MS standard constant
Now, in any long winded loop, simple call the only method:
oDoEvents.GetInputState
API function that will determine if we need to DoEvents:
Private Declare Function GetQueueStatus Lib "user32" (ByVal fuFlags As Long) As Long
Don't forget to destroy your object when you are through with it!
Set oDoevents =
Nothing
(I chose this method name to "honor" John for his article.)
Thanks and good luck!