function in recent posts, here's a simple example to demonstrate its use in a multi-window scenario:
Code: Select all
Enumeration Windows
#Window1
#Window2
#Window3
EndEnumeration
Enumeration Gadgets
#Button1a
#Button1b
#Button2
#Button3
#Text1a
#Text1b
#Text2
#Text3
#Label1
#Label2
EndEnumeration
Enumeration Timers
#Timer1
#Timer2
#Timer3
EndEnumeration
Procedure Open_Window2()
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#Window2, #PB_Any, #PB_Any, 400, 200, "Window 2", wFlags)
EditorGadget(#Text2, 10, 10, 380, 130)
ButtonGadget(#Button2, 10, 150, 380, 40, "Close Window 2")
AddWindowTimer(#Window2, #Timer2, 1000)
ResizeWindow(#Window2, WindowX(#Window2) - (WindowWidth(#Window2) / 2) - 15,
#PB_Ignore, #PB_Ignore, #PB_Ignore)
DisableGadget(#Button1a, 1)
ProcedureReturn
EndProcedure
Procedure Window2_EventHandler(event.i)
Select event
Case #PB_Event_CloseWindow
windowClosed = #True
Case #PB_Event_Timer
SetWindowTitle(#Window2,
"Window 2 - " + FormatDate("%hh:%ii:%ss", Date()))
Case #PB_Event_Gadget
Select EventGadget()
Case #Button2
windowClosed = #True
Case #Text2
Select EventType()
Case #PB_EventType_Focus
SetGadgetText(#Text2, "")
Case #PB_EventType_Change
SetGadgetText(#Text1a, GetGadgetText(#Text2))
EndSelect
EndSelect
EndSelect
If windowClosed
DisableGadget(#Button1a, 0)
RemoveWindowTimer(#Window2, #Timer2)
CloseWindow(#Window2)
EndIf
ProcedureReturn
EndProcedure
Procedure Open_Window3()
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#Window3, #PB_Any, #PB_Any, 400, 200, "Window 3", wFlags)
EditorGadget(#Text3, 10, 10, 380, 130)
ButtonGadget(#Button3, 10, 150, 380, 40, "Close Window 3")
AddWindowTimer(#Window3, #Timer3, 1000)
ResizeWindow(#Window3, WindowX(#Window3) + (WindowWidth(#Window3) / 2) + 15,
#PB_Ignore, #PB_Ignore, #PB_Ignore)
DisableGadget(#Button1b, 1)
ProcedureReturn
EndProcedure
Procedure Window3_EventHandler(event.i)
Select event
Case #PB_Event_CloseWindow
windowClosed = #True
Case #PB_Event_Timer
SetWindowTitle(#Window3,
"Window 3 - " + FormatDate("%hh:%ii:%ss", Date()))
Case #PB_Event_Gadget
Select EventGadget()
Case #Button3
windowClosed = #True
Case #Text3
Select EventType()
Case #PB_EventType_Focus
SetGadgetText(#Text3, "")
Case #PB_EventType_Change
SetGadgetText(#Text1b, GetGadgetText(#Text3))
EndSelect
EndSelect
EndSelect
If windowClosed
DisableGadget(#Button1b, 0)
RemoveWindowTimer(#Window3, #Timer3)
CloseWindow(#Window3)
EndIf
ProcedureReturn
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#Window1, #PB_Any, #PB_Any, 400, 250, "A Multi-Window Example", wFlags)
TextGadget(#Label1, 10, 10, 200, 20, "Window 2 mirror:")
TextGadget(#Label2, 10, 105, 200, 20, "Window 3 mirror:")
EditorGadget(#Text1a, 10, 30, 380, 65, #PB_Editor_WordWrap)
EditorGadget(#Text1b, 10, 125, 380, 65, #PB_Editor_WordWrap)
ButtonGadget(#Button1a, 10, 200, 185, 40, "Open Window 2")
ButtonGadget(#Button1b, 205, 200, 185, 40, "Open Window 3")
AddWindowTimer(#Window1, #Timer1, 1000)
ResizeWindow(#Window1, #PB_Ignore, WindowY(#Window1) - WindowHeight(#Window1) - 30,
#PB_Ignore, #PB_Ignore)
Repeat
event = WaitWindowEvent()
Select EventWindow()
Case #Window2
Window2_EventHandler(event)
Case #Window3
Window3_EventHandler(event)
Case #Window1
Select event
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Timer
SetWindowTitle(#Window1, "A Multi-Window Example - " +
FormatDate("%hh:%ii:%ss", Date()))
Case #PB_Event_Gadget
Select EventGadget()
Case #Button1a
If Not IsWindow(#Window2)
Open_Window2()
EndIf
Case #Button1b
If Not IsWindow(#Window3)
Open_Window3()
EndIf
Case #Text1a
Select EventType()
Case #PB_EventType_Focus
SetGadgetText(#Text1a, "")
Case #PB_EventType_Change
If IsGadget(#Text2)
SetGadgetText(#Text2, GetGadgetText(#Text1a))
EndIf
EndSelect
Case #Text1B
Select EventType()
Case #PB_EventType_Focus
SetGadgetText(#Text1b, "")
Case #PB_EventType_Change
If IsGadget(#Text3)
SetGadgetText(#Text3, GetGadgetText(#Text1b))
EndIf
EndSelect
EndSelect
EndSelect
EndSelect
Until appQuit = 1
Each window's events are handled exclusively by its own event handler, working gracefully without any issues.