It is the gadgets on each window that you use. Make gadget names unique per window... Then when the gadget in that window is pressed you do what you need to do in that window...
Code: Select all
Enumeration
#Window_1
#Window_0
EndEnumeration
Enumeration
#Button_REFILL_LI_1
#Button_OPN1
#Button_CLR_LI_1
#ListIcon_1
#Button_REFILL_LI_0
#Button_OPN2
#Button_CLR_LI_0
#ListIcon_0
EndEnumeration
Structure VisualDesignerGadgets
Gadget.l
EventFunction.l
EndStructure
Global NewList EventProcedures.VisualDesignerGadgets()
; we make a simple neat procedure to fill nonsense into the Listicon gadgets that we can call by button
; and indicate where to act!
Procedure FilltheList(where)
For x = 0 To 12 ; we are going to fill the ListIconGagdet
jerk = Random(3)+3 ; from 3 - 6
For h = 0 To jerk
chrs = Random(25) + 65 ; capital letters of english alphabet
letter$ = Chr(chrs) ; change that random into a character
word$ = word$ + letter$ ; add it to the word
Next
line$ = Str(x)
AddGadgetItem(where, -1, word$) ; throw it on the list indicated
word$ = "" ; simple cleanup
Next
EndProcedure
Procedure Button_REFILL_LI_1_Event(Window, Event, Gadget, Type)
Debug "#Button_REFILL_LI_1"
FilltheList(#ListIcon_1) ; call out LI Fill procedure
EndProcedure
Procedure Button_OPN1_Event(Window, Event, Gadget, Type)
Debug "#Button_OPN1"
HideWindow(#Window_1, 1) ; hide the second window
HideWindow(#Window_0, 0) ; unhide firstsecond
EndProcedure
Procedure Button_CLR_LI_1_Event(Window, Event, Gadget, Type)
Debug "#Button_CLR_LI_1"
ClearGadgetItemList(#ListIcon_1)
EndProcedure
Procedure ListIcon_1_Event(Window, Event, Gadget, Type)
Debug "#ListIcon_1" ; using SELECT CASE this time
Result = GetGadgetState(#ListIcon_1) ; what row clicked on?
Select Result
Case -1
ProcedureReturn -1
Default
Text$ = GetGadgetItemText(#ListIcon_1, Result)
MessageRequester("PICK","You selected: "+text$+Chr(10)+"Please press [OK] and"+Chr(10)+"do something Else!")
Text$ = "" ; simple cleanup
EndSelect
EndProcedure
Procedure Button_REFILL_LI_0_Event(Window, Event, Gadget, Type)
Debug "#Button_REFILL_LI_0"
FilltheList(#ListIcon_0) ; call out LI Fill procedure
EndProcedure
Procedure Button_OPN2_Event(Window, Event, Gadget, Type)
Debug "#Button_OPN2"
HideWindow(#Window_0, 1) ; hide the first window
HideWindow(#Window_1, 0) ; unhide the second
EndProcedure
Procedure Button_CLR_LI_0_Event(Window, Event, Gadget, Type)
Debug "#Button_CLR_LI_0"
ClearGadgetItemList(#ListIcon_0)
EndProcedure
Procedure ListIcon_0_Event(Window, Event, Gadget, Type)
Debug "#ListIcon_0"
; you clicked on something! we can do something here like pop up a message box about what you clicked
Result = GetGadgetState(#ListIcon_0) ; what row was clicked on
If Result = -1
Goto Exit_LI0_Loop ; gonna do this with SELECT CASE next time
ElseIf Result > -1
Text$ = GetGadgetItemText(#ListIcon_0, Result)
MessageRequester("PICK","You selected: "+text$+Chr(10)+"Please press [OK] and"+Chr(10)+"do something Else!")
Text$ = "" ; simple cleanup
EndIf
Exit_LI0_Loop:
; **** just a jump out
EndProcedure
Procedure RegisterGadgetEvent(Gadget, *Function)
If IsGadget(Gadget)
AddElement(EventProcedures())
EventProcedures()\Gadget = Gadget
EventProcedures()\EventFunction = *Function
EndIf
EndProcedure
Procedure CallEventFunction(Window, Event, Gadget, Type)
ForEach EventProcedures()
If EventProcedures()\Gadget = Gadget
CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
LastElement(EventProcedures())
EndIf
Next
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 5, 5, 400, 244, "Window 0", #PB_Window_SystemMenu | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Window_0))
ListIconGadget(#ListIcon_0, 15, 20, 225, 170, "Column1", 100, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
RegisterGadgetEvent(#ListIcon_0, @ListIcon_0_Event())
ButtonGadget(#Button_CLR_LI_0, 15, 195, 225, 35, "CLEAR LIST 0")
RegisterGadgetEvent(#Button_CLR_LI_0, @Button_CLR_LI_0_Event())
ButtonGadget(#Button_OPN2, 245, 165, 145, 65, "OPEN WINDOW 1")
RegisterGadgetEvent(#Button_OPN2, @Button_OPN2_Event())
ButtonGadget(#Button_REFILL_LI_0, 250, 20, 140, 40, "REFILL")
RegisterGadgetEvent(#Button_REFILL_LI_0, @Button_REFILL_LI_0_Event())
EndIf
EndIf
EndProcedure
Procedure Open_Window_1()
If OpenWindow(#Window_1, 417, 5, 400, 243, "Window 1", #PB_Window_Invisible | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
If CreateGadgetList(WindowID(#Window_1))
ListIconGadget(#ListIcon_1, 160, 15, 225, 170, "Column1", 100, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
RegisterGadgetEvent(#ListIcon_1, @ListIcon_1_Event())
ButtonGadget(#Button_CLR_LI_1, 165, 195, 220, 35, "CLEAR LIST 1")
RegisterGadgetEvent(#Button_CLR_LI_1, @Button_CLR_LI_1_Event())
ButtonGadget(#Button_OPN1, 10, 165, 145, 65, "OPEN WINDOW 0")
RegisterGadgetEvent(#Button_OPN1, @Button_OPN1_Event())
ButtonGadget(#Button_REFILL_LI_1, 10, 20, 140, 40, "REFILL")
RegisterGadgetEvent(#Button_REFILL_LI_1, @Button_REFILL_LI_1_Event())
EndIf
EndIf
EndProcedure
Open_Window_1()
Open_Window_0()
; now that the windows are open... we need to put someht8ing in our lists
FilltheList(#ListIcon_0)
FilltheList(#ListIcon_1)
Repeat
Event = WaitWindowEvent()
Gadget = EventGadget()
Type = EventType()
Window = EventWindow()
Select Event
Case #PB_Event_Gadget
CallEventFunction(Window, Event, Gadget, Type)
EndSelect
Until Event = #PB_Event_CloseWindow
End
Seee you can't click on a control that isn't displayed... but you can call one that isn't displayed... if you know the infernal secret!
Let us say I wanted to call the Clear LI_0 button on the first window from the second window, I could... passing parameters to it would be difficult {that means I haven't fully figured this out yet!!} but I could simply add the function call to my program and it would. I could even create a button on the second window that would emulate a press on the first.
If you need to.
This means you do not have to duplicate code. My Restaurant POS program is barely 500k just because of this!!!