当前位置:编程学习 > VB >>

高手求救!!!在线跪求!

如果用QueryPerformanceFrequency和QueryPerformanceCounter做高精度时钟
比如,按下A键,0.5毫秒做鼠标左键单击,再按下A建停止!就像鼠标连点一样!
就是这个控制应该怎么做?
TIMER控件,觉得好慢!不用上面这2个函数,还有没有精确到1毫秒的函数或控件的!
对这个控制问题,怎么搞?高手救命!在线等!
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Function My_Delay(sSeconds As Long)   '延时函数 Delay(毫秒)
    
   Dim Begin As Long
     Begin = GetTickCount
     a = 0
     Do While a < sSeconds
     GetTickCount -Begin < sSeconds
     DoEvents
     Loop
End Function

Private Sub Command1_Click()
My_Delay 10000
End Sub
VB本身就在短计时上性能不佳,还是要不勉强了。 我不是要做延时函数!我想做鼠标连点!
引用 1 楼 dbcontrols 的回复:
VB code
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Function My_Delay(sSeconds As Long)   '延时函数 Delay(毫秒)
    
   Dim Begin As Long
     Begin = GetTickCount
     a……
哦,明白了,吃现成的啊

引用 3 楼 changfengguiqu 的回复:
我不是要做延时函数!我想做鼠标连点!

引用 1 楼 dbcontrols 的回复:
VB code
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Function My_Delay(sSeconds As Long) '延时函数 Delay(毫秒)

Dim Begin As Lo……
引用楼主 changfengguiqu 的回复:
如果用QueryPerformanceFrequency和QueryPerformanceCounter做高精度时钟
比如,按下A键,0.5毫秒做鼠标左键单击,再按下A建停止!就像鼠标连点一样!
就是这个控制应该怎么做?
TIMER控件,觉得好慢!不用上面这2个函数,还有没有精确到1毫秒的函数或控件的!
对这个控制问题,怎么搞?高手救命!在线等!

Timer的最高精确时间大概在1/18秒,也就是说接近50毫秒,要精确的就用1楼的代码里那个API吧。 1ms做不到。
请测试如下代码:
Option Explicit
Dim i As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Form_Load()
    Do
        i = GetTickCount
        DoEvents
        If i <> GetTickCount Then
            i = GetTickCount
            Debug.Print i
        End If
    Loop
End Sub



下面为输出示例:间隔都在10ms以上。
 66899656 
 66899671 
 66899687 
 66899703 
 66899718 
 66899734 
 66899750 
 66899765 
 66899781 
 66899796 
 66899812 
 66899828 
 66899843 
 66899859 
 66899875 
 66899890 
 66899906 
 66899921 
 66899937 
 66899953 
 66899968 
 66899984 
 66900000 
 66900015 
 66900031 
 66900046 
 66900078
Private Sub Form_Load()
    i = GetTickCount
    Do
        DoEvents
        If i <> GetTickCount Then
            i = GetTickCount
            Debug.Print i
        End If
    Loop
End Sub
这个好看点,但是间隔没变,15 ms左右
引用 7 楼 yiguangqiang88 的回复:
VB code
Private Sub Form_Load()
    i = GetTickCount
    Do
        DoEvents
        If i <> GetTickCount Then
            i = GetTickCount
            Debug.Print i
        End If
    Loop
……

打印出来耗时很长的 
引用 8 楼 aisac 的回复:
打印出来耗时很长的
改一下测试:

Option Explicit
Dim i As Long, a(10) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Form_Load()
Dim n As Byte
    Do
        i = GetTickCount
        DoEvents
        If i <> GetTickCount Then
            i = GetTickCount
            a(n) = i
            n = n + 1
        End If
        If n > 9 Then Exit Do
    Loop
    For n = 0 To 9
        Debug.Print a(n)
    Next
End Sub


结果:
 68390093 
 68390109 
 68390125 
 68390140 
 68390156 
 68390171 
 68390187 
 68390203 
 68390218 

呵呵,我可以做到1ms间隔,基本在1ms内
引用 10 楼 wowfiowow 的回复:
呵呵,我可以做到1ms间隔,基本在1ms内
也是用的GetTickCount这个api? 直接调用Object_DblClick不行吗? 10楼是收工数据还是自动生成的啊 估计也是用的楼主的那2个api函数。求证:GetTickCount的最低时间间隔在15ms左右
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,