Of course you could always let the VD create the program loop for you. I learned to code in PB that way (coming from QB4.5) and I have been pretty happy with it.
EXAMPLE:
Code: Select all
Enumeration
#Window_0
EndEnumeration
Enumeration
#Button_2
#Text_HAPPEN
#Button_1
EndEnumeration
Structure VisualDesignerGadgets
Gadget.l
EventFunction.l
EndStructure
Global NewList EventProcedures.VisualDesignerGadgets()
Procedure Button_2_Event(Window, Event, Gadget, Type)
Debug "#Button_2"
SetGadgetText(#Text_HAPPEN, "* BUTTON 2 PRESSED!!! *")
EndProcedure
;Procedure Text_HAPPEN_Event(Window, Event, Gadget, Type)
; Debug "#Text_HAPPEN"
; *** You don't need an event for this since nothing happens if it is clicked on
;EndProcedure
Procedure Button_1_Event(Window, Event, Gadget, Type)
Debug "#Button_1"
SetGadgetText(#Text_HAPPEN, "BUTTON ONE PRESSED!!!")
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, 187, "GADGET WINDOW", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
; If CreateGadgetList(WindowID(#Window_0))
ButtonGadget(#Button_1, 15, 55, 370, 50, "GADGET 1")
RegisterGadgetEvent(#Button_1, @Button_1_Event())
TextGadget(#Text_HAPPEN, 15, 10, 370, 30, "", #PB_Text_Center | #PB_Text_Border)
; RegisterGadgetEvent(#Text_HAPPEN, @Text_HAPPEN_Event()) ; *** not needed
ButtonGadget(#Button_2, 15, 110, 370, 55, "GADGET 2")
RegisterGadgetEvent(#Button_2, @Button_2_Event())
; EndIf ; ***** The second set are REM out because 4.4+ does not need them
EndIf
EndProcedure
Open_Window_0()
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
All the code was created by the VD and I REM out what isn't really needed. I modify this to create a MAP now instead of a list but the essence is the same.
