simulate PB events

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

simulate PB events

Post 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
Last edited by eddy on Wed Oct 08, 2008 2:07 am, edited 5 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Is

Code: Select all

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

Code: Select all

PokeW( @wp+0,GadgetID)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

true

| edit | fixed
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

thx, very nice
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
HeX0R
Addict
Addict
Posts: 1205
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post 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!
Brice Manuel

Post 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.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: simulate PB events

Post by NoahPhense »

Very kewl...

- np
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

FSW posted similar code found here: viewtopic.php?t=15470
Phoenix
Enthusiast
Enthusiast
Posts: 141
Joined: Sun Sep 04, 2005 2:25 am

Re: simulate PB events

Post 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?
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post 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.
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post 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) ;)
Brice Manuel

Post 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.
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post 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)
Brice Manuel

Post 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.
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

Great !
Post Reply