例子代码:高速DoEvents

enmity 2002-03-14 12:16:35
Private Declare Function GetInputState Lib "user32" () As Long

Public Sub NewDoEvents()
If GetInputState() <> 0 Then DoEvents
End Sub

...全文
28 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
fuxc 2002-03-14
  • 打赏
  • 举报
回复
我通常的用法:

  Dim intTmp As Integer
  intTmp = 0
  Do While True
    '.....
    intTmp = intTmp + 1
    If intTmp > 200 Then '200次一个DoEvents
      DoEvents
      intTmp = 0
    End If
  Loop
fuxc 2002-03-14
  • 打赏
  • 举报
回复
我通常的用法:

Dim intTmp As Integer
intTmp = 0
Do While True
'.....
intTmp = intTmp + 1
If intTmp > 200 Then '200次一个DoEvents
DoEvents
intTmp = 0
End If
Loop
shawls 2002-03-14
  • 打赏
  • 举报
回复


我来up一下!

bafenghan 2002-03-14
  • 打赏
  • 举报
回复
谢谢了!
suolan 2002-03-14
  • 打赏
  • 举报
回复
JG
lqf 2002-03-14
  • 打赏
  • 举报
回复
谢谢,非常有用
lihonggen0 2002-03-14
  • 打赏
  • 举报
回复
不错

谢谢enmity (灵感之源) !!!
yokel 2002-03-14
  • 打赏
  • 举报
回复
不错,简单有效
HowardOK 2002-03-14
  • 打赏
  • 举报
回复
能否解释一下,我不明白!!谢谢了!
xxlroad 2002-03-14
  • 打赏
  • 举报
回复
fuxc 2002-03-14
  • 打赏
  • 举报
回复
呵呵,茅塞顿开!
jyd30 2002-03-14
  • 打赏
  • 举报
回复
Very Good! I want to use the function.
xdd1125 2002-03-14
  • 打赏
  • 举报
回复
希望更多的人将自已的心得和经验与他人分享,你快乐我也快乐!
:)
Mike_sun 2002-03-14
  • 打赏
  • 举报
回复
hehe
enmity 2002-03-14
  • 打赏
  • 举报
回复
这样做是为了节省运算时间,提高运行速度。
enmity 2002-03-14
  • 打赏
  • 举报
回复
to:HowardOK(小B)

其实,这是判断系统工作队列中是否有项目(如鼠标单击、鼠标移动、对象绘制、时钟、键盘输入等等),如果有,就让系统执行它。其实DoEvents的原型是这样的:

DoEvents->GetInputState->GetQueueStatus

API声明和函数如下:
'The GetQueueStatus function indicates the type of messages found in the calling thread's message queue. Here are the flags that GetQueueStatus uses :
'QS_ALLEVENTS An input, WM_TIMER, WM_PAINT, WM_HOTKEY, or posted message is in the queue.
'QS_ALLINPUT Any message is in the queue.
'QS_ALLPOSTMESSAGE A posted message (other than those listed here) is in the queue.
'QS_HOTKEY A WM_HOTKEY message is in the queue.
'QS_INPUT An input message is in the queue.
'QS_KEY A WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message is in the queue.
'QS_MOUSE A WM_MOUSEMOVE message or mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on).
'QS_MOUSEBUTTON A mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on).
'
'QS_MOUSEMOVE A WM_MOUSEMOVE message is in the queue.
'QS_PAINT A WM_PAINT message is in the queue.
'QS_POSTMESSAGE A posted message (other than those listed here) is in the queue.
'QS_SENDMESSAGE A message sent by another thread or application is in the queue.
'QS_TIMER A WM_TIMER message is in the queue.
'
'(I believe that GetInputState() is a GetQueueStatus(QS_HOTKEY Or QS_KEY Or QS_MOUSEBUTTON))
'
'With these constants you can create your own GetInputState function that fits your needs. For example you can create a custom function that issues DoEvents when it'll detects not only a Keyboard or Mouse
'Key input, but also a WM_PAINT signal.
'Why 's that? 'cause in your loop you might need to update the screen so you must let your custom function process the specific signal.
'Look at this :

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 Const QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
Private Const QS_INPUT = (QS_MOUSE Or QS_KEY)
Private Const QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT Or QS_HOTKEY)

Private Declare Function GetQueueStatus Lib "user32" (ByVal qsFlags As Long) As Long


Public Function cGetInputState() As Boolean

Dim o_lngRet As Long

o_lngRet = GetQueueStatus(QS_HOTKEY Or QS_KEY Or QS_MOUSEBUTTON Or QS_PAINT)

cGetInputState = (o_lngRet <> 0)

End Function



enmity 2002-03-14
  • 打赏
  • 举报
回复
楼上,如果按照你的做法,使用MOD 运算更好。
tg123 2002-03-14
  • 打赏
  • 举报
回复
hehe

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧