Page 5 of 9

Posted: Mon Dec 24, 2007 10:18 pm
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...

Posted: Mon Dec 24, 2007 11:19 pm
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.

Posted: Mon Dec 24, 2007 11:24 pm
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.

Posted: Mon Dec 24, 2007 11:25 pm
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.

Posted: Mon Dec 24, 2007 11:31 pm
by srod
No loop required :

Code: Select all

ID = GetDlgCtrlID_(*sender\hWnd)

Posted: Mon Dec 24, 2007 11:34 pm
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!

Posted: Mon Dec 24, 2007 11:35 pm
by srod
You're welcome. :)

Posted: Tue Dec 25, 2007 1:11 am
by DoubleDutch
Thanks SRod :)

Fred, if you see this... That should be a native command.

Posted: Tue Dec 25, 2007 1:13 pm
by electrochrisso
Like the Hat srod. :D
Happy New Year to you. :D

Posted: Tue Dec 25, 2007 1:26 pm
by srod
:) Sparkie started that off!

A happy merry messy new year to you as well.

Posted: Tue Dec 25, 2007 1:34 pm
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:

Posted: Tue Jan 01, 2008 11:50 pm
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.

Posted: Wed Jan 02, 2008 12:09 pm
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.

Posted: Wed Jan 02, 2008 1:31 pm
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.

Posted: Wed Jan 02, 2008 3:21 pm
by GeoTrail
The download link for EasyEvent doesn't work.