Verfasst: 27.03.2008 13:16
Hatten wird schon so oft
Thread über globale Variablen handshaken.
FF 

Thread über globale Variablen handshaken.
Code: Alles auswählen
;- Konstanten
Enumeration ; Window ID
#Window
EndEnumeration
Enumeration ; Menu ID
#Menu
EndEnumeration
Enumeration ; MenuItem ID
#Menu_Exit
EndEnumeration
Enumeration ; Statusbar ID
#Statusbar
EndEnumeration
Enumeration ; Gadget ID
#List
EndEnumeration
; ***************************************************************************************
Procedure UpdateWindow()
Protected x,y,dx,dy
Protected mn,st,tb
x = 0
y = 0
mn = MenuHeight()
st = StatusBarHeight(#StatusBar)
;tb = ToolBarHeight(#ToolBar)
dx = WindowWidth(#Window)
dy = WindowHeight(#Window) - mn - st - tb
ResizeGadget(#List, x, y, dx, dy)
EndProcedure
Procedure WriteLog(Info.s)
Protected temp.s
temp = FormatDate("%YYYY.%MM.%DD %HH:%II:%SS - ", Date()) + Info
AddGadgetItem(#List, -1, temp)
If CountGadgetItems(#List) > 500
RemoveGadgetItem(#List, 0)
EndIf
EndProcedure
;- Globale Variablen
Global exit = 0
Global ExitThread = #False
Declare MyThread(dummy.l)
;- Fenster
style = #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 400, 300, "Fenster", style)
; Menu
If CreateMenu(#Menu, WindowID(#Window))
MenuTitle("&Datei")
MenuItem(#Menu_Exit, "Be&enden")
EndIf
; Statusbar
CreateStatusBar(#Statusbar, WindowID(#Window))
; Gadgets
If CreateGadgetList(WindowID(#Window))
ListViewGadget(#List, 0,0,0,0)
EndIf
; Start Thread
hThread = CreateThread(@MyThread(), 0)
;-- Hauptschleife
Repeat
event = WaitWindowEvent()
window = EventWindow()
menu = EventMenu()
type = EventType()
Select event
Case #PB_Event_Menu
Select menu
Case #Menu_Exit
Exit = 1
EndSelect
Case #PB_Event_Gadget
Case #PB_Event_CloseWindow
Exit = 1
Case #PB_Event_Repaint
Case #PB_Event_SizeWindow
UpdateWindow()
Case #PB_Event_MoveWindow
Case #PB_Event_ActivateWindow
Case #PB_Event_SysTray
EndSelect
Until Exit And ExitThread
EndIf
End
Procedure MyThread(dummy.l)
Protected count
WriteLog("Start Thread")
Repeat
Delay(1000)
count + 1
WriteLog("Counter: " +Str(count))
Until Exit
WriteLog("Ende Thread")
ExitThread = #True
EndProcedure
