return ----> events

Just starting out? Need help? Post your questions and find answers here.
lambor734
User
User
Posts: 40
Joined: Sun Dec 19, 2010 7:46 pm
Location: ovanaro

return ----> events

Post by lambor734 »

Hi All ,
How can the following example, gave back events?
Last edited by lambor734 on Thu Jan 27, 2011 11:46 am, edited 1 time in total.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: return ----> events

Post 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:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
lambor734
User
User
Posts: 40
Joined: Sun Dec 19, 2010 7:46 pm
Location: ovanaro

Re: return ----> events

Post 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:
Last edited by lambor734 on Thu Jan 27, 2011 11:46 am, edited 1 time in total.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: return ----> events

Post 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.
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Post Reply