小弟最近想做个网络游戏挂机程序。。原来在VB里面可以用SLEEP来实现每一步的操作。但是在VB6里面使用SLEEP函数程序就象死机一样。。但是还是再用POSTMESSAGE函数想目标句柄发送信息。。这样不利于在挂机过程中的停止。。可有高手指点一下。。

解决方案 »

  1.   

    sleep 10000
    doevents     
    即可
      

  2.   

    自己写个延时函数即可:
    http://topic.csdn.net/t/20050805/17/4191555.html
      

  3.   

    Private Sub waite(y)
    Dim startime As Date, endtime As Date
    Const seconds = "s"
    startime = Time
    endtime = Time
    Do While DateDiff(seconds, startime, endtime) < y
      endtime = Time()
      DoEvents
    Loop
    End Sub
      

  4.   


    试下这样,Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private Declare Function GetInputState Lib "user32" () As LongPrivate Sub Delay(DelayTime As Long)
        Dim i As Long
        Dim EndTime As Long
        EndTime = GetTickCount + DelayTime
        Do Until GetTickCount > EndTime
            i = i + 1
            If GetInputState Then DoEvents
            If i = 100000 Then
                Sleep 10
                i = 0
            End If
        Loop
    End Sub
      

  5.   

    上面的代码不会使得CPU使用率是100%,但是也有个问题就是在这段时间内如果拖动标题栏或者点击菜单,延时就会不准确了。