Using event handlers - (EasyVENT version 3.2)

Developed or developing a new product in PureBasic? Tell the world about it.
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Post by mrjiles »

srod, is there a way to find the gadget that the event is being processed for? I read through the manual and noticed references to hWnd.l and item.l but am not sure if this is what I need (or how to implement).

Basically, if I have a gadget with an ID of 1, with a mouse enter event, when the mouse enters the gadget and the event is triggered, is there a way for the triggered event to know the ID of the gadget that originally called it (whew!)?


Edit: Discovered that hwnd returns the ID that Windows? assigns to the gadget... am now trying to map that ID to the PB ID...
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi,

it's easy enough. In your event handler the hWnd field of the *sender structure can be used as in the following example :

Code: Select all

;*********************************************************************************
XIncludeFile "EasyVENT.pbi"
  DisableExplicit
;*********************************************************************************

Declare.l ButtonClick(*sender.PB_Sender)

OpenWindow(0, 100, 100, 200, 200, "", #PB_Window_SystemMenu |#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)

CreateGadgetList(WindowID(0))
  ButtonGadget(1, 5, 15, 80, 24, "Click button") 

  SetEventHandler(GadgetID(1), #OnButtonClick, @ButtonClick())

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End

Procedure.l ButtonClick(*sender.PB_Sender)
  If *sender\hWnd = GadgetID(1)
    Debug "Click on gadget 1"
  EndIf
  PerformDefaultWinProcessing(*sender) ;To handle the #OnMouseUp event.
ProcedureReturn #Event_ReturnDefault 
EndProcedure
By the way, I placed the Window's handle (hWnd) in the *sender structure rather than the Purebasic gadget# because EasyVENT can be used with non-PB controls as well, i.e. with controls created directly with CreateWindowEx_() etc.
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I think he means something a bit more general, like:

Code: Select all

id=IDfromHWND(*sender\hWnd)  ; <- this is a "made up" command - it doesn't really exist! ;)
But I think only fred/freak will know if there is an internal table that can reverse the process? Such a command would be *really* useful at times though.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Post by mrjiles »

Thanks for the reply srod and doubledutch. I just created a loop to loop through the possible values and compare them and it works fine.

srod: I will investigate your code further.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

No loop required :

Code: Select all

ID = GetDlgCtrlID_(*sender\hWnd)
I may look like a mule, but I'm not a complete ass.
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Post by mrjiles »

srod wrote:No loop required :

Code: Select all

ID = GetDlgCtrlID_(*sender\hWnd)

Reverse process found! Works great and is probably a ton faster than looping. Thanks srod!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're welcome. :)
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Thanks SRod :)

Fred, if you see this... That should be a native command.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

Like the Hat srod. :D
Happy New Year to you. :D
PureBasic! Purely the best 8)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:) Sparkie started that off!

A happy merry messy new year to you as well.
I may look like a mule, but I'm not a complete ass.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

I am going to have to get one. :)
And I hope it does not get as messy as last year as I ended up with texta drawings all over my face. (too rude to say what they said). :lol:
PureBasic! Purely the best 8)
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Post by mrjiles »

@srod, found an issue with EasyVent on 4.20 Beta 1: #OnItemSelected with ListViewGadget is no longer working.

EDIT: #OnItemSelected works if you use keyboard keys to select options, not if you use the mouse.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I haven't as yet upgraded to 4.2, will do so presently.

However, I find it hard to believe that this event is not working as it's based purely on api stuff. In the same misfunctioning code, are you using a #OnMouseUp event by any chance?

I will test PB 4.2 in the next few minutes.


**EDIT : problem confirmed. Looking into it.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

mrjiles wrote:@srod, found an issue with EasyVent on 4.20 Beta 1: #OnItemSelected with ListViewGadget is no longer working.

EDIT: #OnItemSelected works if you use keyboard keys to select options, not if you use the mouse.
Seems to be some alteration with the way PB selects items when multi-select is turned off. I would guess that PB is now using the #LB_SETCURSEL message.

Anyhow, EasyVENT now gets around this and thus the problem (as far as EasyVENT is concerned) is fixed.

See the first post for the download link.
I may look like a mule, but I'm not a complete ass.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

The download link for EasyEvent doesn't work.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Post Reply