Click to See Complete Forum and Search --> : How to know when the mouse has left the trayicon area?
sp1k
February 14th, 2005, 10:50 PM
I am wondering how I can know when the mouse has hovered over the trayicon and when it has left.
I tried _TrackMouseEvent() with WM_MOUSELEAVE but then I used the HWND to the application that own the trayicon and that didn't work...
So I need to know how to get the HWND to the trayicon.
Or is there another way?
kkez
February 15th, 2005, 01:47 AM
If you craeate the trayicon you should have specified a callback message (es WM_TRAYNOTIFY), and when you receive that message lParam will be one of WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_LBUTTONUP and so on. So you should trap WM_MOUSEMOVE message and check whether the mouse is inside the icon or not.
sp1k
February 15th, 2005, 05:58 AM
Yes that is true, I have tested it but didn't like it cuz it's cinda buggy.
I found out the placement of the icon on the screen and then used the GetCursorPos and PtInRect to know if the mouse is inside the trayicon, to do this I also had to remove some pixels from the trayicons sides to know when the mouse hovered/leaved the trayicon (otherwise you dont get the WM_MOSEMOVE?).
But if I do as I described and the user moves the mouse arrow quite fast over the trayicon the cursor misses the points around the trayicon and I don't get the hover and/or the leave message... :(
UPDATE:
I figured it out, don't know if it's the best and fastest way but it's works lika a charm.
When the mousecursor hovers over the trayicon I setup a WH_MOUSE hook, and when the mouse has left the trayicon the hook checks if the mouse is insite the trayicon's rectangle or not.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.