16,554
社区成员
发帖
与我相关
我的任务
分享
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Dim uID As Long
uID = timeSetEvent(100, 10, AddressOf CALLBACK_Timer, 0, TIME_CALLBACK_FUNCTION Or TIME_PERIODIC)
' 这个就是TimeSetEvet的回调函数!
Public Function CALLBACK_Timer(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long) As Long
t = t + 1
Debug.Print("Timer", t)
End Function
Public Class Form1
Public Delegate Sub TimerEventHandler(ByVal uID As UInt32, _
ByVal uMsg As UInt32, _
ByRef dwUser As UInt32, _
ByVal dw1 As UInt32, _
ByVal dw2 As UInt32)
Public Declare Function timeSetEvent _
Lib "winmm.dll" (ByVal uDelay As UInt32, _
ByVal uResolution As UInt32, _
ByVal lpFunction As TimerEventHandler, _
ByRef dwUser As UInt32, _
ByVal uFlags As UInt32) As UInt32
Private mCount As Integer
Private mUpdate As Action(Of String)
Private mTimerCallback As TimerEventHandler
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mCount = 0
mUpdate = Sub(txt) Label1.Text = txt
mTimerCallback = AddressOf CALLBACK_Timer
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim uID = timeSetEvent(10, 10, mTimerCallback, 0, 1)
End Sub
Public Sub CALLBACK_Timer(ByVal uID As UInt32, _
ByVal uMsg As UInt32, _
ByRef dwUser As UInt32, _
ByVal dw1 As UInt32, _
ByVal dw2 As UInt32)
mCount += 1
Label1.BeginInvoke(mUpdate, CStr(mCount))
End Sub
End Class
mUpdate = Sub(txt) Label1.Text = txt
Dim uID As UInt32
Delegate Sub tywt(ByVal obj As Object) '声明一个通用委托
Public WT_dspDEBUG As New tywt(AddressOf dspDEBUG)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
uID = timeSetEvent(1000, 10, AddressOf CALLBACK_Timer, 0, 1)
End Sub
' 这个就是TimeSetEvet的回调函数!
Public Function CALLBACK_Timer(ByVal uID As UInt32, ByVal uMsg As UInt32, ByVal dwUser As UInt32, ByVal dw1 As UInt32, ByVal dw2 As UInt32) As UInt32
t = t + 1
Me.BeginInvoke(WT_dspDEBUG, t)
Debug.Print("Timer", t)
End Function
Sub dspDEBUG(ByVal t)
Label1.Text = t.ToString
End Sub
Public Class Form1
Public Delegate Sub TimerEventHandler(ByVal uID As UInt32,
ByVal uMsg As UInt32,
ByRef dwUser As UInt32,
ByVal dw1 As UInt32,
ByVal dw2 As UInt32)
Public Declare Function timeSetEvent _
Lib "winmm.dll" (ByVal uDelay As UInt32,
ByVal uResolution As UInt32,
ByVal lpFunction As TimerEventHandler,
ByRef dwUser As UInt32,
ByVal uFlags As UInt32) As UInt32
Private mCount As Integer
Private mUpdate As Action(Of String)
Private mTimerCallback As TimerEventHandler
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
mCount = 0
mUpdate = Sub(txt) Label1.Text = txt
mTimerCallback = AddressOf CALLBACK_Timer
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim uID = timeSetEvent(10, 10, mTimerCallback, 0, 1)
End Sub
Public Sub CALLBACK_Timer(ByVal uID As UInt32,
ByVal uMsg As UInt32,
ByRef dwUser As UInt32,
ByVal dw1 As UInt32,
ByVal dw2 As UInt32)
mCount += 1
Label1.BeginInvoke(mUpdate, CStr(mCount))
End Sub
End Class
Declare Function timeKillEvent Lib "winmm.dll" (ByVal id As UInt32) As UInt32
Private Delegate Sub TimerEventHandler(ByVal id As UInt32, ByVal msg As UInt32, ByRef userCtx As UInt32, ByVal rsv1 As UInt32, ByVal rsv2 As UInt32)
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As UInt32, ByVal uResolution As UInt32, ByVal lpFunction As TimerEventHandler, ByRef dwUser As UInt32, ByVal uFlags As UInt32) As UInt32