views:

108

answers:

3

In Mac OS X's Cocoa Framework, there are Tracking Rects, which effectively allows you to register an area of your view and get callback messages when the mouse enters or leaves.

Is there a similar API in Windows? I'd like to avoid using a timer to call GetCursorPos() every x interval.

It could be that they're named something totally different and it's quite trivial, but I've failed to find anything so far.

+2  A: 

TrackMouseEvent, this will send you a WM_MOUSELEAVE message when the mouse leaves your window, and also hover notifications if the mouse doesn't move for a while.

If you want a tracking rect smaller than your window, than you have to do that yourself.

John Knoeller
+1  A: 

Catch WM_MOUSEMOVE in your window.

Ritsaert Hornstra
This message appears to only get posted if I don't have my mouse over a child control like a button.
Drarok
@Drarok: You might catch the message in your message loop and not dispatch the message. Here you can convert the coordinte or just call GetCursorPos(). This way you won't need to subclass all your windows.
Ritsaert Hornstra
+1  A: 

You can install a mouse hook to capture mouse events.

taspeotis