can i use the SetTimer() api function in "shot" way(just 1 time instead a time cyle)?
Printable View
can i use the SetTimer() api function in "shot" way(just 1 time instead a time cyle)?
Yes, very simply. In your timer procedure, simply destroy the timer
Code:Public Sub OneShotTimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal TimerID As Long, ByVal Tick As Long)
KillTimer hWnd, TimerID
End Sub
' sample call
SetTimer Me.hWnd, [yourID], 10, AddressOf OneShotTimerProc
see the code:
(thes is a control that simulates the multithread and works fine)Code: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 Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliseconds As Long)
Private lTimerId As Long
Public Sub CreateThread(vNewValue As Long)
lTimerId = SetTimer(UserControl.hWnd, 100&, ByVal 5000, ByVal vNewValue)
End Sub
Public Sub DestroyThread()
If lTimerId Then
lTimerId = KillTimer(UserControl.hWnd, lTimerId)
lTimerId = 0
End If
End Sub
like you see i don't have access direct to sub(in control). but thanks for the information. i can put a boolean variable inside the sub(in module) for works 1 time.
these is the only problem these control have:(
what you think about these control?
The vNewValue you are setting the timer's callback procedure to, you do have access to that, correct?
If so, it should be a standard timer callback sub like the OneShotTimerProc in previous reply. Kill the timer there, once it fires
I don't think I fully understand the scenario
better is show you: http://www.mediafire.com/?4mmfvqmmhfh2gv0
(i don't have atachment space)
in a module i have the procedure: here i must use the variable boolean for don't use, again the sub.
in form i have 1 controls(for 2 threads(number of thread must be = controls)).
and heres how use it:
thanksCode:Private Sub Command1_Click()
MultiThread2.CreateThread AddressOf sub1
MultiThread1.CreateThread AddressOf sub2
End Sub
Private Sub Command3_Click()
MultiThread2.DestroyThread
MultiThread1.DestroyThread
End Sub