I concur with Kuron - download CodeArchiv - there are examples for all sorts of interesting things in there. Some of them need tweaking to run under the most recent versions of PB. In the Windows\MultipleWindows subfolder you will find a couple of ways of achieving what you discuss, but here's one way.
Code: Select all
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
#Window_1
#Window_2
EndEnumeration
;}
;{ Menu bars
Enumeration
#Menu_Window_0
EndEnumeration
;}
;{ Menu/Toolbar items
Enumeration
#Menu_Window_0_Window_1
#Menu_Window_0_Window_2
EndEnumeration
;}
;{ Gadgets
Enumeration
#Calendar_0
#ExplorerList_1
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 450, 200, 400, 420, "Window 0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
If CreateMenu(#Menu_Window_0, WindowID(#Window_0))
MenuTitle("Window")
MenuItem(#Menu_Window_0_Window_1, "Window 1")
MenuItem(#Menu_Window_0_Window_2, "Window 2")
EndIf
EndIf
EndProcedure
Procedure OpenWindow_Window_1()
If OpenWindow(#Window_1, 488, 274, 400, 400, "Window 1", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar, WindowID(#Window_0))
CalendarGadget(#Calendar_0, 75, 60, 245, 195)
EndIf
EndProcedure
Procedure OpenWindow_Window_2()
If OpenWindow(#Window_2, 526, 340, 400, 400, "Window 2", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar, WindowID(#Window_0))
ExplorerListGadget(#ExplorerList_1, 20, 10, 310, 330, "c:\")
EndIf
EndProcedure
OpenWindow_Window_0()
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Calendar_0
ElseIf EventGadget = #ExplorerList_1
EndIf
; /////////////////
Case #PB_Event_Menu
EventMenu = EventMenu()
If EventMenu = #Menu_Window_0_Window_1
OpenWindow_Window_1()
ElseIf EventMenu = #Menu_Window_0_Window_2
OpenWindow_Window_2()
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
End
ElseIf EventWindow = #Window_1
CloseWindow(#Window_1)
ElseIf EventWindow = #Window_2
CloseWindow(#Window_2)
EndIf
EndSelect
ForEver
;
;}
I usually organise big projects as follows:-
1) One master .pb file which just contains XInclude references to everything else the project needs, usually called something like appThingy.pb. I don't put any executable code in here at all.
2) Seperate .pbi files for each different window/dialog/'class' and one for the event loop too. Although PB isn't intrinsically an OOP language (see other articles on the forum on that topic ad nauseum), I usually seperate procedures into functional units based upon some kind of common project class (storage file, preferences file, business object whatever)
Window files I start frmThingy1.pbi (for form because I came from VB), (maybe wdw for window would be more sensible), Class files I start clsThingy2.pbi etc. The event loop I just call Event.pbi.
3) appThingy.pb includes all the form and class files and then the event loop.
4) I use a PureBasic project file to hang all the files together so I can get to them easily from inside the IDE.
5) I even put change control information into a pbi file and add that to the project so that I can even get to that from withing the IDE - I just don't 'include' it in the source code that is compiled.