Hi all,
I am writting a GUI library using win 32 api. My laguage is Nim, but that is not a matter here.
For mimicking vb.net style, i have designed an event driven method in this library. Every control class in my lib has some public members called events. And all of them are UINTs. like --
ButtonClass.click = BN_CLICKED
FormClass.click = WM_LBUTTONDOWN
Each class has an AddHandler function. This is the signature.
AddHandler(evt, pFn)
-evt = events
-pFn = function pointer
So this AddHandler will add all user functions and appropriate messages in a list. Then, in the WndProc function, i can loop through this list and call appropriate function. Everything seems to be ok so far.
But I want my control classes to handle mouse enter, hover and leave events too. This created a problem. I can't find a general control mouse enter message in win api. I know that button's use BCN_HOTITEMCHANGE and it worked for me. But i can't find a solution which is applicable for every controls. How to fix this problem.
I just tested with TrackMouseEvent. This was my testing scenario-
1. When mouse pointer hovered over any control, i get a WM_MOUSELEAVE message. And when pointer comes back to client area, i get a WM_MOUSEMOVE message.
2. So i started tracking mouse in WM_MOUSELEAVE and stopped tracking in WM_MOUSEMOVE. My intention was to get the mouse hover message on the top of every controls. But this was not worked as in intend. Any help ?
Some extra info--
1. For all control class, i have created a CTL_MOUSE_ENTER, CTL_MOUSE_HOVER, CTL_MOUSE_LEAVE messages.
2. Then i added function pointers for these events and keep it in a list.
3. In WndProc, i want to loop through this list and call the function.
4. To find which control is under mouse pointer, i use GetMousePos & ScreenToClient functions.
5. And then i tried with WindowFromPoint function but didn't worked.
6. Then i tried to find the control with the RECT of the control, but didn't worked.
Now, all my experiments were failed.
What I have tried:
proc TrackMouse*(handle : HWND) =
var lpTME : TTRACKMOUSEEVENT
lpTME.cbSize = cast[DWORD](sizeof(TTRACKMOUSEEVENT))
lpTME.dwFlags = TME_HOVER or TME_LEAVE
lpTME.dwHoverTime = 100 #HOVER_DEFAULT
lpTME.hwndTrack = handle
discard COMCTL32_TrackMouseEvent(lpTME)