Hello all,
Attached is a quick demo to do button rollover using a method which I haven't seen elsewhere: watching the WM_SETCURSOR message. Other ways of handling this that I've seen involve subclassing windows for the WM_MOUSEMOVE message. I find this is much simpler, and perhaps more flexible.

Posted on 2002-12-14 00:05:21 by chorus
Chorus, nice.

You might want to find a better way to detect when the mouse leaves the button area, though. I was able to get the button to change to blue and stay blue by moving the mouse cursor outside of the button area really fast. I could also do the same thing by resizing the window.

If you don't mind sacrificing Win95 compatibility you could use TrackMouseEvent to get WM_MOUSELEAVE messages.
Posted on 2002-12-14 07:23:41 by iblis
iblis, Thank you.
Win95 compatibility is my primary reason for not using TrackMouseEvent. I also want to avoid subclassing and hooks this way. Since the WM_SETCURSOR message gets passed up to a window's parent by DefWindowProc it works very simply -- you just have to handle it in your Application Main Window.

As for the button staying highlighted, perhaps the most straightforward solution is to install a timer and a corresponding proc.


TimerProc PROC hWin,uMsg,idEvent,cTime:DWORD
cmp ButtonRollover,NULL
je @@DoNothing
invoke WindowFromPoint,msg.pt.x,msg.pt.y
cmp eax,ButtonRollover
je @@DoNothing
@@ClearButton: mov eax,ButtonRollover
mov ButtonRollover,NULL
invoke InvalidateRect,eax,NULL,TRUE
@@DoNothing: ret
TimerProc ENDP

Posted on 2002-12-14 11:33:16 by chorus
Nice work!

I could have used this with my Custom Control Tuturial....

Posted on 2002-12-14 22:28:47 by NaN
If u enter a green square, and then mantain the left mouse button clicked, and go outside the window, the square gets blue until u enter again in the window.

Posted on 2003-01-02 00:09:05 by r00t