哪位高手能给个回调函数的例子
谁能给个回调函数的例子?
回调函数方面的知识 从来没接触过,希望给个比较 清晰地例子,一定要跨工程调用。
------解决方案--------------------
clsTimer code
Event Notify(ByVal somenum As Double)
Public Sub StartTimer()
Call BeginTimer(Me) 'Start the timer
End Sub
Public Sub Notifyme(ByVal anum As Double)
RaiseEvent Notify(anum) 'Create an event with the result
End Sub 'as a parameter
Public Sub StopTimer()
Call EndTimer
End Sub
Private Sub Class_Terminate()
Call EndTimer 'Make sure the timer is stopped
End Sub
Standard module code:
Global timerid As Long
Dim thetimer As clsTimer
Public Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Public Sub EndTimer()
Dim retval As Long
retval = KillTimer(0, timerid)
End Sub
Public Sub BeginTimer(ByRef Timerobj As clsTimer)
Set thetimer = Timerobj
timerid = SetTimer(0, 0, 1, AddressOf TimerProc)
End Sub
Public Sub TimerProc(ByVal hwnd As Long, ByVal umsg As Long, _
ByVal idEvent As Long, ByVal dwtime As Long)
Dim counter As Long
Dim theanswer As Double
KillTimer 0, timerid 'Stop the timer
For counter = 1 To 15000000 'Do some work here
theanswer = theanswer + counter
Next counter
thetimer.Notifyme (theanswer) 'Work is done. Pass the result
End Sub 'as a parameter.
------解决方案--------------------
MSDN上就有个关于回调的EnumWindows例子
回调函数方面的知识 从来没接触过,希望给个比较 清晰地例子,一定要跨工程调用。
------解决方案--------------------
clsTimer code
Event Notify(ByVal somenum As Double)
Public Sub StartTimer()
Call BeginTimer(Me) 'Start the timer
End Sub
Public Sub Notifyme(ByVal anum As Double)
RaiseEvent Notify(anum) 'Create an event with the result
End Sub 'as a parameter
Public Sub StopTimer()
Call EndTimer
End Sub
Private Sub Class_Terminate()
Call EndTimer 'Make sure the timer is stopped
End Sub
Standard module code:
Global timerid As Long
Dim thetimer As clsTimer
Public Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Public Sub EndTimer()
Dim retval As Long
retval = KillTimer(0, timerid)
End Sub
Public Sub BeginTimer(ByRef Timerobj As clsTimer)
Set thetimer = Timerobj
timerid = SetTimer(0, 0, 1, AddressOf TimerProc)
End Sub
Public Sub TimerProc(ByVal hwnd As Long, ByVal umsg As Long, _
ByVal idEvent As Long, ByVal dwtime As Long)
Dim counter As Long
Dim theanswer As Double
KillTimer 0, timerid 'Stop the timer
For counter = 1 To 15000000 'Do some work here
theanswer = theanswer + counter
Next counter
thetimer.Notifyme (theanswer) 'Work is done. Pass the result
End Sub 'as a parameter.
------解决方案--------------------
MSDN上就有个关于回调的EnumWindows例子