Using event handlers - (EasyVENT version 3.2)
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...
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...
Hi,
it's easy enough. In your event handler the hWnd field of the *sender structure can be used as in the following example :
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.
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
I may look like a mule, but I'm not a complete ass.
- DoubleDutch
- Addict
- Posts: 3220
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
I think he means something a bit more general, like:
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.
Code: Select all
id=IDfromHWND(*sender\hWnd) ; <- this is a "made up" command - it doesn't really exist! ;)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system
No loop required :
Code: Select all
ID = GetDlgCtrlID_(*sender\hWnd)
I may look like a mule, but I'm not a complete ass.
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!
- DoubleDutch
- Addict
- Posts: 3220
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
Thanks SRod 
Fred, if you see this... That should be a native command.

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
https://reportcomplete.com <- School end of term reports system
- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
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.
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.
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.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.
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.