I'm trying to getting used to handle multiple windows with a single event loop
and I want to be able to close each of these windows with the ESC key, so
the code looks like this:
Code: Select all
EnableExplicit
; Create a constant for each window
Enumeration
#MainWindow
#OtherWindow
EndEnumeration
; Declare procedures
Declare MainWindowEvents(event)
Declare OtherWindowEvents(event)
; *************************************************************************************************
Procedure MainWindowEvents(event)
; Exit on ESC press
If KeyboardReleased(#PB_Key_Escape)
ProcedureReturn 1
EndIf
Select event
Case #PB_Event_CloseWindow
ProcedureReturn 1
EndSelect
EndProcedure
Procedure OtherWindowEvents(event)
; Close on ESC press
If KeyboardReleased(#PB_Key_Escape)
CloseWindow(#OtherWindow)
EndIf
Select event
Case #PB_Event_CloseWindow
CloseWindow(#OtherWindow)
EndSelect
EndProcedure
; *************************************************************************************************
Procedure Main()
Protected event, exit
; We need this for ExamineKeyboard() / KeyboardReleased()
InitKeyboard()
OpenWindow(#MainWindow, 10, 10, 100, 100, "Title 1")
OpenWindow(#OtherWindow, 110, 110, 100, 100, "Title 2")
Repeat
event = WaitWindowEvent()
ExamineKeyboard()
; Check events for each window separately!
Select EventWindow()
Case #MainWindow
exit = MainWindowEvents(event)
Case #OtherWindow
OtherWindowEvents(event)
EndSelect
Until exit
EndProcedure
; *************************************************************************************************
; Call the main procedure
Main()
leads to a non-responding second window and the app crashes when I hit
the close button of it...
When the debugger is not active, the two windows behave just fine.
Do I use ExamineKeyboard() in a wrong way?