|
-
Nov 9th, 2011, 10:28 AM
#1
Thread Starter
PowerPoster
[vb6] - using SetTimer
can i use the SetTimer() api function in "shot" way(just 1 time instead a time cyle)?
-
Nov 9th, 2011, 12:46 PM
#2
Re: [vb6] - using SetTimer
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
-
Nov 9th, 2011, 12:54 PM
#3
Thread Starter
PowerPoster
Re: [vb6] - using SetTimer
 Originally Posted by LaVolpe
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:
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
(thes is a control that simulates the multithread and works fine)
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?
-
Nov 9th, 2011, 01:01 PM
#4
Re: [vb6] - using SetTimer
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
-
Nov 9th, 2011, 01:09 PM
#5
Thread Starter
PowerPoster
Re: [vb6] - using SetTimer
 Originally Posted by LaVolpe
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:
Code:
Private Sub Command1_Click()
MultiThread2.CreateThread AddressOf sub1
MultiThread1.CreateThread AddressOf sub2
End Sub
Private Sub Command3_Click()
MultiThread2.DestroyThread
MultiThread1.DestroyThread
End Sub
thanks
Last edited by joaquim; Nov 9th, 2011 at 01:13 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|