How to use TrackMouseEvent ?

New to FreeBASIC? Post your questions here.
kcvinu
Posts: 173
Joined: Oct 07, 2015 16:44
Location: Keralam, India

How to use TrackMouseEvent ?

Postby kcvinu » Oct 07, 2018 20:17

Hi all,
I am playing with some win api gui code. I am sorry because, this code is not in FB, but in Nim. But i am sure that this question is related to WinAPI and language is not a problem. Thats why i am asking here.
I have GUI and WndProc function. For an experiment, i just re arrange my wndproc and made something like jose roca's WinFormsX library, but slightly different.
I have a question,
How do we set mouse enter and mouse leave events for our control classes ?
this is my control class

Code: Select all

type   
    RichEditClass* = ref object of Control
        event* : REdEvents

    REdEvents* = object   '# See, these are events
        textChange* : UINT
        mouseEnter* : UINT
        mouseLeave* : UINT

And this is the cunstructor of this class.

Code: Select all

result.ctype = cType.RichEdit      '# result itself is the object .
result.isTracking = false
result.eventList = @[]         '# an empty list
result.mouseEvents = @[]         '# separate list for mouse events
result.event.textChange = EN_CHANGE   '# these are events.
result.event.mouseEnter = CTL_MOUSE_ENTER
result.event.mouseLeave = CTL_MOUSE_LEAVE

After creating a rich edit control variable, user can add handler of each events with AddHandler function.
This is the function

Code: Select all

proc AddHandler*(me : RichEditClass, event : UINT, pfn : EvtHandler ) =  '# me is  like "self" in python, "this" in c++
    var anEvt : Event_And_Handler   '# Its a type with 2 members
    anEvt.msg = event      '# the event alias message
    anEvt.handler = pfn      '# the function pointer
    if event == CTL_MOUSE_ENTER or event == CTL_MOUSE_LEAVE :  '# separating mouse events
        me.mouseEvents.add(anEvt)
    else :
        me.eventList.add(anEvt)
#End proc AddHandler-----------------------------------   

So users can set their event handler functions with a control class. In my WndProc, i can loop through this list and call appropriate functions. This is the function calling method in wndproc.

Code: Select all

case message   '# Case statement
 of WM_COMMAND :
        # First set up the message info
        e.nCode = cast[UINT](HIWORD(wParam)) # Notification code
        e.cnID = cast[UINT](LOWORD(wParam))  # Control ID
        e.sender = cast[HWND](lParam)        # Handle of Control
       
        if Hw_n_Obj.hasKey(e.sender) == true :   # A Table - [Hwnd, ControlClass] - A dictionary lookup
            var ThisControl = Hw_n_Obj[e.sender]  # We got the control object
            for j in ThisControl.eventList :   # every control has an event list, lets loop through the list
                if j.msg == e.nCode :         # EventList is a tuple [event_msg, handler_fn]
                    procCall(j.handler(e))   # here we can call the handler function.
                    break

So in this setup, I just tested with the TrackMouseEvent function. (dwFlags = TME_HOVER or TME_LEAVE)
This was my testing scenario.
1. When the mouse entered on any controls, my wndproc function will get a WM_MOUSEMOVE message.
2. At that time i called TrackMouseEvent and for getting the mouse hover message even when the mouse pointer is on top of the controls. But that test failed. So how to implement the TrackMouseEvent here.
jj2007
Posts: 881
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: How to use TrackMouseEvent ?

Postby jj2007 » Oct 07, 2018 21:40

See Why is there no WM_MOUSEENTER message?
You will have to subclass the control, though - details here.
kcvinu
Posts: 173
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: How to use TrackMouseEvent ?

Postby kcvinu » Oct 09, 2018 6:44

@jj2007,
Thanks a lot. :)

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests