Hey all,
Has anyone had any experience with using TrackMouseEvent.

My basic goal is to create a button with a similar style to toolbar buttons, ie run the mouse over them and they appear raised, when the mouse leaves they return back to looking 'flat'.

I think I have seen a tutorial around which describes this but im not sure.

Any info would be great

Posted on 2002-03-31 22:31:44 by huh
Use WM_MOUSEMOVE window message.
Posted on 2002-03-31 22:37:24 by comrade
That tells me that the mouse is moving in my window, but it does not tell me when it leaves :(

Combining that with mouse capture is a possible solution, but since that is susceptable to errors im trying to use TrackMouseEvent
Posted on 2002-03-31 22:42:18 by huh
I also usually use WM_MOUSEMOVE, but that is a personal preference and I like to have compatibility with as many versions as I can.

But to answer your question:

TrackMouseEvent is the function to let Windows know which window you would like to have tracked. Fill out the TRACKMOUSEEVENTTYPE structure and pass that to TrackMouseEvent.

hwndTrack = handle of the window to track
dwFlags = TME_LEAVE (0002h)

Now Windows will generate a WM_MOUSELEAVE event when the mouse exits the specified window. At the same time, tracking of the mouse will stop so if they re-enter the window you must again call TrackMouseEvent if further tracking is needed.

Note: This function is only valid for Win 98+:alright:
Posted on 2002-04-01 08:58:21 by Graebel
here is an example of how I do it..

;First check if we are in the window
invoke GetCursorPos, addr pt
invoke GetWindowRect, hWnd, addr rt
invoke PtInRect, addr rt, pt.x, pt.y

.IF eax != 0 ;Mouse is in window
invoke GetCapture
.IF eax != hWnd
;Window wasn't capturing the mouse which means the mouse
;probably just entered so you should probably redraw here
;as well as set the capture so you know when the mouse leaves
invoke SetCapture, hWnd
.ELSE ;Mouse has left window
invoke ReleaseCapture
Posted on 2002-04-03 04:54:19 by Stan