Code: Select all
EnableExplicit
Global Semaphore.i
Declare Main()
Declare Thread(*Dummy)
Enumeration #PB_Event_FirstCustomValue
#Thread_Finished
#Thread_AddText
EndEnumeration
Enumeration
#MAIN_WINDOW
#EDITOR_WINDOW
#MENU
#FILE_RUN
#FILE_QUIT
EndEnumeration
Procedure Main()
Protected Exit.b
Protected Event.i
Protected Thread.i
#Width = 400
#Height = 400
#Space = 10
OpenWindow(#MAIN_WINDOW, 100, 100, #Width, #Height, "Main Window")
EditorGadget(#EDITOR_WINDOW, #Space, #Space, #Width - (#Space * 2), #Height - MenuHeight() - (#Space * 2), #PB_Editor_ReadOnly)
CreateMenu(#MENU, WindowID(#MAIN_WINDOW))
MenuTitle("File")
MenuItem(#FILE_RUN, "Run")
MenuItem(#FILE_QUIT, "Quit")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Exit = #True
Case #Thread_AddText
AddGadgetItem(#EDITOR_WINDOW, -1, PeekS(EventData()))
; Goto last character (auto scroll)
SendMessage_(GadgetID(#EDITOR_WINDOW), #EM_SETSEL, -1, -1)
SignalSemaphore(Semaphore)
Case #Thread_Finished
DisableMenuItem(#MENU, #FILE_RUN, #False)
SignalSemaphore(Semaphore)
Case #PB_Event_Menu
Event = EventMenu()
Select Event
Case #FILE_RUN
DisableMenuItem(#MENU, #FILE_RUN, #True)
Thread = CreateThread(@Thread(), #Null)
Case #FILE_QUIT
Exit = #True
EndSelect
EndSelect
Until Exit
; Kill thread if needed...
If IsThread(Thread) : KillThread(Thread) : EndIf
FreeMenu(#MENU)
CloseWindow(#MAIN_WINDOW)
EndProcedure
Procedure Thread(*Dummy)
Protected LoopCnt.i
Protected Output.s
For LoopCnt = 1 To 10000
Output = "This string is number " + Str(LoopCnt)
; Send output to gui and wait for gui to process...
Semaphore = CreateSemaphore()
PostEvent(#Thread_AddText, #Null, #Null, #Null, @Output)
WaitSemaphore(Semaphore)
FreeSemaphore(Semaphore)
Next
; Done, let the gui know were done...
Semaphore = CreateSemaphore()
PostEvent(#Thread_Finished, #Null, #Null, #Null, #Null)
WaitSemaphore(Semaphore)
FreeSemaphore(Semaphore)
EndProcedure
Main()
End
Is there a way around it besides HideMenu(), which messes up the coordinates of the editorgadget ?