Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
Type ThreadToken
hnd As Long
Limit As Long
End Type
Function PBMain() As Long
Local hDlg As Dword
Dialog New Pixels, 0, "Test Code",300,300,300,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"No Thread", 30,10,140,20
Control Add Button, hDlg, 200,"Thread", 30,40,140,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local i,iStart,iEnd, junk As Long
Static Token As ThreadToken
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
iStart = GetTickCount
For i = 1 To 500000
' Dialog Set Text Cb.Hndl, "Test Code " + Str$(i) '5.8s, blinks
' Dialog Set Text Cb.Hndl, "Test Code " + Str$(i) : Sleep 1 '50s, no blink, freeze
If (i Mod 50) = 0 Then Dialog Set Text Cb.Hndl, "Test Code " + Str$(i) '0.28s, blinks
' If (i Mod 50) = 0 Then Dialog Set Text Cb.Hndl, "Test Code " + Str$(i) : Sleep 1 '1.0s, no blink
Next i
iEnd = GetTickCount
? Format$((iEnd - iStart)/1000,3) & " seconds"
ElseIf Cb.Msg = %WM_Command And Cb.Ctl = 200 And Cb.CtlMsg = %BN_Clicked Then
Token.hnd = Cb.Hndl
Token.Limit = 5000
Thread Create SetCaptionTitle(VarPtr(Token)),To junk
End If
End Function
Thread Function SetCaptionTitle (ByVal TokenAddress As Long) As Long
Local i,iStart,iEnd As Long, TokenPtr As ThreadToken Ptr
iStart = GetTickCount
TokenPtr = TokenAddress
For i = 1 To @TokenPtr.Limit
' Dialog Set Text @TokenPtr.hnd,"hello" + Str$(i) '5.0s, no blink
If (i Mod 50) = 0 Then Dialog Set Text @TokenPtr.hnd,"hello" + Str$(i) '0.1s, no blink
Next i
iEnd = GetTickCount
? Format$((iEnd - iStart)/1000,3) & " seconds"
End Function
'gbs_00729
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm