managing multiple windows
Posted: Sun Dec 02, 2012 11:57 am
I'm just getting started with PB and want to create a window which opens another window when you click a button. I've got it working but when you close the 2nd window using the default "x" in the top right corner, both the windows are closed and not just the 2nd one. Can anyone tell me what I'm doing wrong? Thanks.
edit: I've just been looking at the help file and I see that there might be an easier way to do this using #PB_Window_Invisible and ParentWindowID in the OpenWindow() command. Not sure how to do this though so any help gratefully received.
Code: Select all
Enumeration
#window1
#window2
#button1_1
#button1_2
#button2_1
#button2_2
EndEnumeration
OpenWindow(#window1, 0, 0, 230, 90, "Window 1", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#button1_1, 10, 10, 200, 25, "open window 2")
ButtonGadget(#button1_2, 10, 50, 200, 25, "Test")
OpenWindow(#window2, 0, 0, 230, 90, "Window 2", #PB_Window_SystemMenu)
ButtonGadget(#button2_1, 10, 10, 200, 25, "Test")
ButtonGadget(#button2_2, 10, 50, 200, 25, "Close this window")
HideWindow(#window2,1)
Repeat
Event = WaitWindowEvent()
Window = EventWindow()
Gadget = EventGadget()
Select Window
Case #window1
Select Event
Case #PB_Event_Gadget
Select Gadget
Case #button1_1 : HideWindow(#window2, 0) ; show window 2
Case #button1_2 : Debug "window 1 Test button clicked"
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
Case #window2
Select Event
Case #PB_Event_Gadget
Select Gadget
Case #button2_1 : Debug "window 2 Test button clicked"
Case #button2_2 : HideWindow(#window2, 1) ; hide window 2
EndSelect
Case #PB_Event_CloseWindow
HideWindow(#window2, 1) ; hide window 2
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow