How do you post custom gadget's events to the PB EventLoop?

Windows specific forum
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

How do you post custom gadget's events to the PB EventLoop?

Post by Demivec »

Here is a typical PB event loop that's been roughed out:

Code: Select all

Repeat
  event = WaitWindowEvent(10)
  If event = #PB_Event_CloseWindow
    Break
  ElseIf event = #PB_Event_Menu
    If EventMenu() = #Shortcut_Escape: Break: EndIf
  ElseIf event = #PB_Event_Gadget
    Select EventGadget()
      Case #gadget_1
        Select EventType()
        Case #PB_EventType_LeftClick
          ;Do something
        Case #PB_EventType_RightClick     
          ;Do something
        EndSelect
      Case #gadget_2
          ;Do something
    EndSelect
  ElseIf #customEvent_1
    ;Do something
  ElseIf #customEvent_2
    ;Do something
  EndIf
ForEver
Examining posts in the forum I know how to post custom events to the message queue read by the PB Event loop. Want I would like to do is post events that can be detected for a particular gadget (i.e. having a #PB_Event_Gadget type) and then being able to work with EventGadget() and EventType(). How can I accomplish this?

Would this be a case of trying to squeeze too much out of these functions? Or would it result in something that would break in a future PB version? If so I will have to make do with custom_events for the custom_gadgets involved. It just wouldn't make much sense to have to check for events from gadgets in more than one place (if I can avoid it). :wink:
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 »

This is the simplest way to send custom messages

Code: Select all

Import ""
  PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport

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
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

Thankyou, it definately does the job. What file is it imported from? I know it's one that is already opened but without its name I won't be able to browse its other contents.
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 »

>> What file is it imported from?
Gadget.lib :wink:
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
Post Reply