对与再大循环里 加入 DoEvents却是可以使应用程序响应其他程序,但是 DoEvents 也会很大程度上影响循环的速度,所以一般情况我这样用
If GetInputState Then DoEvents
虽然多了个判断语句,但速度上确快了很多
Private Declare Function GetInputState Lib "user32" () As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
Dim s As Long
s = GetTickCount
For i = 1 To 1000000
DoEvents
Next
MsgBox GetTickCount - s
End Sub
Private Sub Command2_Click()
Dim s As Long
s = GetTickCount
For i = 1 To 1000000
If GetInputState Then DoEvents
Next
MsgBox GetTickCount - s
End Sub
以上情况五次测试结果分别为: Command1 : 5398,4852,4820,6318,5428Command2 :203,202,203,203测试环境:Win Vista U版 + VB6( 2.5G 内存 + AMD 双核 1.7G )呵呵,以此测试结果, 根据有没有 采用 GetInputState API 的 DoEvents 时间差很大噢~~
原文链接:https://www.f2er.com/vb/263140.html