But the normal behavior is to check one window for events.
the normal way would be to use an OOP-Language for an OO-Surface.
there is no need to activate/disable your windows,
but it can be easier to handle sometimes.
alternatively you can use threads to handle different windows.
each window can have an own event-loop withing its thread.
for such, the communication between windows has to be handled through Globals,
you can't SetGadgetText on a Gadget of a different thread.
but it's not that difficult to handle multiple windows in one event-loop.
I coded a little example, hope I eliminated every bug and typo.
tested it more than once, should be ready.
(ok, a few minutes late, but i coded it for this topic so i will post it.

)
please note that each Gadget needs a unique number.
if you try to put a Button No.9 on Window1, and later a
Textgadget No. 9 on Window 2, the Button will vanish.
so you'l need one single Enum for the Gadgets.
Also keep in mind to use seperate Enums for Windows and Gadgets,
because both lists should start with No.0 and continue without Gaps.
enumerating with other start-numbers or with gaps will cause no Error
but may lower Performance.
of course you don't really need to devide the code into window-cases first.
you could check all the gadgets within the same code-section,
just
because they all have unique numbers.
but also then you should at least seperate them by thick remarks,
and you will need to write a second section that is devided into
window-cases for non-gadget-events like CloseWindow.
in my opinion it's best readable if its clealy devided into sections by
Window-Number, each section handling every event for this window.
[edit]
netmeastro achieved this by using seperate procedures.
[/edit]
questions/suggestions/critics welcome
Code: Select all
;*********************************************************
;*** MoreWindows.pb
;***
;*** Example for use of EventWindow()
;*** to handle multiple Windows
;*** without child/parent
;***
;*** Dec.22, 2006 Kaeru Gaman
;***
;*** PB Ver 4.02 Win
;*********************************************************
EnableExplicit
;*************************************
Enumeration ;Windows
#Win_Main
#Win_Sub1
#Win_Sub2
#Win_Sub3
#Win_Sub4
EndEnumeration
;*************************************
Enumeration ;Gadgets
#Main_But_LaunchSub1
#Main_But_LaunchSub2
#Main_But_LaunchSub3
#Main_Txt_Display
#Sub1_But_TestBeep
#Sub2_But_TestBeep
#Sub3_But_LaunchSub4
#Sub4_Opt_Text1
#Sub4_Opt_Text2
#Sub4_Opt_Text3
EndEnumeration
;*************************************
Procedure OpenSub1()
OpenWindow(#Win_Sub1, -1, -1, 200,150,"Sub1",#PB_Window_ScreenCentered | #PB_Window_SystemMenu )
CreateGadgetList(WindowID(1))
ButtonGadget(#Sub1_But_TestBeep,10,10,60,20,"Beep Deep")
EndProcedure
;*************************************
Procedure OpenSub2()
OpenWindow(#Win_Sub2, -1, -1, 200,150,"Sub2",#PB_Window_ScreenCentered | #PB_Window_SystemMenu )
CreateGadgetList(WindowID(2))
ButtonGadget(#Sub2_But_TestBeep,10,10,60,20,"Beep High")
EndProcedure
;*************************************
Procedure OpenSub3()
OpenWindow(#Win_Sub3, -1, -1, 200,150,"Sub3",#PB_Window_ScreenCentered | #PB_Window_SystemMenu )
CreateGadgetList(WindowID(3))
ButtonGadget(#Sub3_But_LaunchSub4, 70,110,120,30,"Launch Sub4")
EndProcedure
;*************************************
Procedure OpenSub4()
OpenWindow(#Win_Sub4, -1, -1, 200,150,"Sub4",#PB_Window_ScreenCentered | #PB_Window_SystemMenu )
CreateGadgetList(WindowID(4))
OptionGadget(#Sub4_Opt_Text1,20,20,160,20,"Beef")
OptionGadget(#Sub4_Opt_Text2,20,50,160,20,"Lamb")
OptionGadget(#Sub4_Opt_Text3,20,80,160,20,"Fish")
EndProcedure
;*************************************
OpenWindow(#Win_Main,0,0,320,240,"Main", #PB_Window_ScreenCentered | #PB_Window_SystemMenu )
CreateGadgetList(WindowID(0))
ButtonGadget(#Main_But_LaunchSub1,190,120,120,30,"Launch Sub1")
ButtonGadget(#Main_But_LaunchSub2,190,160,120,30,"Launch Sub2")
ButtonGadget(#Main_But_LaunchSub3,190,200,120,30,"Launch Sub3")
TextGadget(#Main_Txt_Display,10,10,160,20, "No Choice yet", #PB_Text_Border)
;*************************************
Define Event.l
Define EXIT.l
Define DisplayTxt$ = "Your Choice is "
;*************************************
Repeat
Event = WaitWindowEvent()
Select EventWindow()
;*********************************************************
;*** Main Window
;*********************************************************
Case #Win_Main
Select Event
Case #PB_Event_Gadget
;*************************************
;** Gadget Events
Select EventGadget()
Case #Main_But_LaunchSub1
OpenSub1()
Case #Main_But_LaunchSub2
OpenSub2()
Case #Main_But_LaunchSub3
OpenSub3()
EndSelect
;*************************************
;** Other Events
Case #PB_Event_CloseWindow
EXIT = 1
EndSelect
;*********************************************************
;*** Sub Window 1
;*********************************************************
Case #Win_Sub1
Select Event
Case #PB_Event_Gadget
;*************************************
;** Gadget Events
Select EventGadget()
Case #Sub1_But_TestBeep
Beep_( 500,300)
EndSelect
;*************************************
;** Other Events
Case #PB_Event_CloseWindow
CloseWindow(#Win_Sub1)
EndSelect
;*********************************************************
;*** Sub Window 2
;*********************************************************
Case #Win_Sub2
Select Event
Case #PB_Event_Gadget
;*************************************
;** Gadget Events
Select EventGadget()
Case #Sub2_But_TestBeep
Beep_(1500,300)
EndSelect
;*************************************
;** Other Events
Case #PB_Event_CloseWindow
CloseWindow(#Win_Sub2)
EndSelect
;*********************************************************
;*** Sub Window 3
;*********************************************************
Case #Win_Sub3
Select Event
Case #PB_Event_Gadget
;*************************************
;** Gadget Events
Select EventGadget()
Case #Sub3_But_LaunchSub4
OpenSub4()
EndSelect
;*************************************
;** Other Events
Case #PB_Event_CloseWindow
CloseWindow(#Win_Sub3)
EndSelect
;*********************************************************
;*** Sub Window 4
;*********************************************************
Case #Win_Sub4
Select Event
Case #PB_Event_Gadget
;*************************************
;** Gadget Events
Select EventGadget()
Case #Sub4_Opt_Text1
SetGadgetText(#Main_Txt_Display, DisplayTxt$ + "Beef")
Case #Sub4_Opt_Text2
SetGadgetText(#Main_Txt_Display, DisplayTxt$ + "Lamb")
Case #Sub4_Opt_Text3
SetGadgetText(#Main_Txt_Display, DisplayTxt$ + "Fish")
EndSelect
;*************************************
;** Other Events
Case #PB_Event_CloseWindow
CloseWindow(#Win_Sub4)
EndSelect
;*********************************************************
;*** End of Window List
;*********************************************************
EndSelect
Until EXIT = 1
End