Page 1 of 2

simulate PB events

Posted: Tue Oct 04, 2005 8:11 pm
by eddy
Simulate or Emulate PB events system...


Code: Select all

ProcedureDLL SimulateGadgetEvent(Gadget, EventType)
   Protected wp=Gadget+EventType<<(SizeOf(Word)*8)
   Protected lp=GadgetID(Gadget)
   ;get parent window
   Protected win=GetParent_(GadgetID(Gadget))
   ;While GetParent_(win) : win=GetParent_(win) : Wend
   ;send message to window
   PostMessage_(win, #WM_COMMAND, wp, lp)
EndProcedure

; ********************
; EXAMPLE by eddy
; ********************

OpenWindow(1, 0, 0, 400, 250, "1", #PB_Window_SystemMenu)
CompilerIf #PB_Compiler_Version<430
   CreateGadgetList(Windiwid(1))
CompilerEndIf
ButtonGadget(10, 5, 5, 55, 55, "10")

OpenWindow(2, 0, 0, 400, 250, "2", #PB_Window_SystemMenu, WindowID(1))
CompilerIf #PB_Compiler_Version<430
   CreateGadgetList(Windiwid(2))
CompilerEndIf
ContainerGadget(100, 0, 0, 200, 200, #PB_Container_Double)
ButtonGadget(20, 5, 5, 55, 55, "20")
CloseGadgetList()

Repeat
   e=WaitWindowEvent()
   w=EventWindow()
   g=EventGadget()
   t=EventType()
      
   Select e
      Case #PB_Event_ActivateWindow
         If EventWindow()=1
            gadget=10
            eventtype=Random(100)
         Else
            gadget=20
            eventtype=#PB_EventType_LeftDoubleClick
         EndIf
         SimulateGadgetEvent(gadget, eventtype)
         Debug "(gadget="+Str(gadget)+") Sending a new event "
         
      Case #PB_Event_Gadget
         Debug "event window="+Str(w)
         Debug "event gadget="+Str(g)
         Debug "event type="+Str(t)
         Debug ""
   EndSelect
Until e=#PB_Event_CloseWindow

Posted: Tue Oct 04, 2005 9:00 pm
by ts-soft
Is

Code: Select all

PokeW( @wp+0,id)
correct ? Or so ?

Code: Select all

PokeW( @wp+0,GadgetID)

Posted: Tue Oct 04, 2005 9:23 pm
by eddy
true

| edit | fixed

Posted: Tue Oct 04, 2005 9:29 pm
by ts-soft
thx, very nice

Posted: Wed Oct 05, 2005 6:34 am
by HeX0R
This comes in very handy!

Not even two weeks ago i searched like hell through the MSDN-Network for exactly this function, but hadn't any luck...

Thx for sharing this!

Posted: Wed Oct 05, 2005 12:33 pm
by Brice Manuel
Very good Eddy! Thank you for sharing. I have been wondering how to do this for the 2D GUI I am working on.

Re: simulate PB events

Posted: Sun Oct 09, 2005 2:35 am
by NoahPhense
Very kewl...

- np

Posted: Sun Oct 09, 2005 3:07 am
by Shannara
FSW posted similar code found here: viewtopic.php?t=15470

Re: simulate PB events

Posted: Sun Oct 09, 2005 4:51 am
by Phoenix
eddy wrote:

Code: Select all

PokeW( @wp+0,GadgetID)
PokeW( @wp+2,EventType)
I don't understand what "wp" is in the example... is has no default value so what value do they hold and where do they come from? How does PokeW work when it doesn't know what "wp" is?

Posted: Sun Oct 09, 2005 10:53 am
by einander
@Phoenix:

WP.w is a empty memory address where you can put any two bytes.
Here POKE is the command to set the contents of WP.
The two bytes are GadgetID and EventType.

Posted: Mon Oct 10, 2005 11:08 pm
by Dräc
Brice Manuel wrote:Very good Eddy! Thank you for sharing. I have been wondering how to do this for the 2D GUI I am working on.
I don’t know if you expect to share a such work, but I would be interesting by using a good library an the subject rather than develop one myselft (because I have already enough job for rest of my game) ;)

Posted: Mon Oct 10, 2005 11:30 pm
by Brice Manuel
I don’t know if you expect to share a such work,
Yes, I will release it as a free LIB when it is more complete. (Right now, only windows, buttons, spinners and sliders are implemented. ) I have a couple of other little things for PB done that I need to do docs for and put online.

Posted: Mon Oct 10, 2005 11:39 pm
by Dräc
Brice Manuel wrote:
I don’t know if you expect to share a such work,
Yes, I will release it as a free LIB when it is more complete. (Right now, only windows, buttons, spinners and sliders are implemented. ) I have a couple of other little things for PB done that I need to do docs for and put online.
To be sure : is it truly to perform a GUI under exclusive mode ? (OpenScreen)

Posted: Mon Oct 10, 2005 11:49 pm
by Brice Manuel
Sorry Eddy about the thread hijack :?
To be sure : is it truly to perform a GUI under exclusive mode ?
2D will work fullscreen or windowed.

Posted: Mon Oct 10, 2005 11:53 pm
by Dräc
Great !