5个回答
展开全部
标准答案如下:
利用API函数实现定时器功能
模块中:
Option Explicit
Public lTimerId As Long
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private Sub TimerProc(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lTimerId As Long, ByVal lTime As Long)
Static i As Long
Form1.Label1.Caption = i
i = i + 1
End Sub
Public Sub StartTimer(lMinute As Long)
lTimerId = SetTimer(0, 0, lMinute, AddressOf TimerProc)
End Sub
Public Function StopTimer(lTimerId As Long) As Long
StopTimer = KillTimer(0, lTimerId)
End Function
窗体中:
Private Sub Form_Load()
StartTimer 1000
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopTimer lTimerId
End Sub
利用API函数实现定时器功能
模块中:
Option Explicit
Public lTimerId As Long
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private Sub TimerProc(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lTimerId As Long, ByVal lTime As Long)
Static i As Long
Form1.Label1.Caption = i
i = i + 1
End Sub
Public Sub StartTimer(lMinute As Long)
lTimerId = SetTimer(0, 0, lMinute, AddressOf TimerProc)
End Sub
Public Function StopTimer(lTimerId As Long) As Long
StopTimer = KillTimer(0, lTimerId)
End Function
窗体中:
Private Sub Form_Load()
StartTimer 1000
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopTimer lTimerId
End Sub
展开全部
和timer功能相同的函数没有!
只能另开一线程才能有相同的功能!
用timer可实现简单的双线程及多个timer实现多线程操作
上面的如果用sleep函数,想想也知道结果的!小延时感觉到功能差不多,但时间长了,程序就不运行了!
只能另开一线程才能有相同的功能!
用timer可实现简单的双线程及多个timer实现多线程操作
上面的如果用sleep函数,想想也知道结果的!小延时感觉到功能差不多,但时间长了,程序就不运行了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
settimer和killtimer,在网上搜xtimer类,可以找到源码
Public Declare Function SetTimer Lib "user32" Alias "SetTimer" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" Alias "KillTimer" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Declare Function SetTimer Lib "user32" Alias "SetTimer" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" Alias "KillTimer" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
api 函数 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
参考多线程编程,不过VB本身就是不支持多线程的,汗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询