Page 1 of 1

return ----> events

Posted: Tue Jan 25, 2011 7:36 pm
by lambor734
Hi All ,
How can the following example, gave back events?

Re: return ----> events

Posted: Tue Jan 25, 2011 9:41 pm
by Rook Zimbabwe
One way is to use GLOBAL VARIABLES

Code: Select all


Global Dim Stuff.l
Global Dim Otherstuff$
global Dim StuffFlag = #False

Macro mm(p)    
Procedure Callback2(hwnd,uMsg,wParam,lParam,uId,uData)
   If hwnd = p
     Stuff = 1000
     Otherstuff$ = "Stuff that happened..."
     Stuffflag = #True
     ; return Events
     
   EndIf
    ProcedureReturn DefSubclassProc(hwnd,uMsg,wParam,lParam)
EndProcedure
  
  SetWindowSubclass(p,@Callback2(),0) 

EndMacro

  ; ----->>> Or otherwise, that are each did it.
Simple...

But I wouldn't put a procedure INSIDE a macro... silly! :mrgreen:

Re: return ----> events

Posted: Wed Jan 26, 2011 9:25 am
by lambor734
I'd like the function of WaitWindowEvent() every moment events are returned.
But your code does not work , Please if you know of another way, you said. :oops:

Re: return ----> events

Posted: Wed Jan 26, 2011 5:27 pm
by Rook Zimbabwe
For me it depends on which version of the Visual Designer you use:

MY VD returns this:

Code: Select all


Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Text_0
  #Button_2
  #Button_1
  #Button_0
EndEnumeration

Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()

Procedure Text_0_Event(Window, Event, Gadget, Type)
  Debug "#Text_0"
EndProcedure

Procedure Button_2_Event(Window, Event, Gadget, Type)
  Debug "#Button_2"
  SetGadgetText(#Text_0, "WINDOW = "+Str(Window)+" :: EVENT = "+Str(Event)+" :: GADGET = "+Str(Gadget) + " :: TYPE + "+Str(Type))
EndProcedure

Procedure Button_1_Event(Window, Event, Gadget, Type)
  Debug "#Button_1"
  SetGadgetText(#Text_0, "WINDOW = "+Str(Window)+" :: EVENT = "+Str(Event)+" :: GADGET = "+Str(Gadget) + " :: TYPE + "+Str(Type))
EndProcedure

Procedure Button_0_Event(Window, Event, Gadget, Type)
  Debug "#Button_0"
  SetGadgetText(#Text_0, "WINDOW = "+Str(Window)+" :: EVENT = "+Str(Event)+" :: GADGET = "+Str(Gadget) + " :: TYPE + "+Str(Type))
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, 348, 117, "Window 0",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    ;If CreateGadgetList(WindowID(#Window_0)) ; used for PB 3.95 -
      ButtonGadget(#Button_0, 10, 60, 105, 40, "BUTT 0")
      RegisterGadgetEvent(#Button_0, @Button_0_Event())
      ButtonGadget(#Button_1, 120, 60, 105, 40, "BUTT 1")
      RegisterGadgetEvent(#Button_1, @Button_1_Event())
      ButtonGadget(#Button_2, 230, 60, 105, 40, "BUTT 2")
      RegisterGadgetEvent(#Button_2, @Button_2_Event())
      TextGadget(#Text_0, 10, 15, 330, 25, "", #PB_Text_Center | #PB_Text_Border)
      RegisterGadgetEvent(#Text_0, @Text_0_Event())
      
    ;EndIf
  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

It looks like you are trying to force OOP on something that is not OOP... My code is as OOPish as I get.