Code: Alles auswählen
;-TOP
; Example ThreadToGUI
IncludeFile "Modul_ThreadToGUI.pb"
Enumeration #PB_Event_FirstCustomValue
#My_Event_ThreadToGUI
EndEnumeration
Structure udtThreadData
ThreadId.i
Cancel.i
; Data
EndStructure
Procedure thFillList(*data.udtThreadData)
Protected text.s, count
UseModule ThreadToGUI
DoSetGadgetText(1, "Stop Fill")
DoStatusBarText(0, 0, "Thread 1 running...")
For count = 1 To 120
text = FormatDate("%HH:%II:%SS - Number ", Date()) + Str(count)
DoAddGadgetItem(0, -1, text)
Delay(1000)
If *data\Cancel
Break
EndIf
Next
DoStatusBarText(0, 0, "Thread 1 finished.")
DoSetGadgetText(1, "Start Fill")
*data\Cancel = 0
UnuseModule ThreadToGUI
EndProcedure
Procedure thFlash(*data.udtThreadData)
Protected count, col
UseModule ThreadToGUI
DoSetGadgetText(2, "Stop Flash")
For count = 0 To 40
For col = 0 To 3
DoStatusBarProgress(0, 1, count * 20 + col * 5)
Select col
Case 0 : DoSetGadgetColor(3, #PB_Gadget_BackColor, RGB(255,0,0))
Case 1 : DoSetGadgetColor(3, #PB_Gadget_BackColor, RGB(255,255,0))
Case 2 : DoSetGadgetColor(3, #PB_Gadget_BackColor, RGB(0,255,0))
Case 3 : DoSetGadgetColor(3, #PB_Gadget_BackColor, RGB(255,255,255))
EndSelect
Delay(1000)
If *Data\Cancel
Break 2
EndIf
Next
Next
DoStatusBarProgress(0, 1, 100)
DoSetGadgetText(2, "Start Flash")
*data\Cancel = 0
UnuseModule ThreadToGUI
EndProcedure
Procedure Main()
Protected event, thread1.udtThreadData, thread2.udtThreadData
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 800, 560, "Thread To GUI Example", #PB_Window_SystemMenu)
CreateStatusBar(0, WindowID(0))
AddStatusBarField(200)
StatusBarText(0, 0, "Thread 1")
AddStatusBarField(200)
AddStatusBarField(#PB_Ignore)
ListViewGadget(0, 0, 0, 800, 500)
ButtonGadget(1, 10, 510, 120, 24, "Start Fill")
ButtonGadget(2, 140, 510, 120, 24, "Start Flash")
StringGadget(3, 710, 510, 80, 24, "State", #PB_String_ReadOnly)
ThreadToGUI::BindEventGUI(#My_Event_ThreadToGUI)
Repeat
event = WaitWindowEvent(10)
Select event
Case #PB_Event_CloseWindow
If IsThread(thread1\ThreadId) Or IsThread(thread2\ThreadId)
MessageRequester("Info", "Threads running...")
Else
Break
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If Not IsThread(thread1\ThreadId)
thread1\ThreadId = CreateThread(@thFillList(), thread1)
Else
thread1\Cancel = 1
EndIf
Case 2
If Not IsThread(thread2\ThreadId)
thread2\ThreadId = CreateThread(@thFlash(), thread2)
Else
thread2\Cancel = 1
EndIf
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()