Date: 02-16-2022
Return to Index
created by gbSnippets
'Primary Code:
'There are 2 basic pieces to the puzzle:
'Create a thread Function to run as the thread
Thread Function NewThread (ByVal x As Long) As Long
'... thread code goes here
End Function
'Create the thread
Thread Create NewThread(0) To hThread
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord, hThread As DWord
Global gString$
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Start", 50,10,100,20
Control Add Label, hDlg, 601,"<threada count>", 50,70,100,20
Control Add Label, hDlg, 602,"<threadb count>", 50,100,100,20
gString$ = "xx"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Thread Create ThreadA(0) To hThread 'new thread
Thread Create ThreadB(0) To hThread 'new thread
End If
End Function
Thread Function ThreadA (ByVal i As Long) As Long
Local p As String Ptr
p = StrPTR(gString$)
Do : Incr i : Control Set Text hDlg, 601, "Thread" + Str$(i)
@p = "rs"
Mid$(gString$, 1) = "ab"
Loop Until i > 4000
End Function
Thread Function ThreadB (ByVal i As Long) As Long
Local p As String Ptr
p = StrPTR(gString$)
Do : Incr i : Control Set Text hDlg, 602, "Thread" + Str$(i)
@p = "45"
Mid$(gString$, 4) = "bc"
Loop Until i > 4000
End Function
'gbs_00443
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm