Could somebody please show me an example code how i can detect if the mouse is over my button or something else so i can change it. Thank you if you can help.
Could somebody please show me an example code how i can detect if the mouse is over my button or something else so i can change it. Thank you if you can help.
You can trap the mouse movement in each of the controls that you wish to use it by subclassing it...
zMan
You can trap WM_MOUSEMOVE, but you can get buggy behavior if you fail to catch when the mouse *leaves* the button. To catch this, you'll need to install a timer that checks if the mouse is still there. When the mouse leaves, just do any cleaning up that you need to do. For example, I use this method to highlight buttons when my mouse is over them, and when the mouse leaves, I reset the original look of the button.
BTW, I recommend a time of about 100 ms for the timer. This seems to work well for me.
--Chorus
Try putting this together...
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
Do you? Why can't you use WM_MOUSEMOVE for both highlighting and de-highlighting? If the new mouse position is over the button, highlight it, and if it's not on the button, de-highlight it.To catch this, you'll need to install a timer that checks if the mouse is still there
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
i dont have any code, but you could sub-class the button and then use WM_MOUSEMOVE for it
"There are three kinds of people in the world...
Those that can count and those that can't."
WM_MOUSEMOVE is only sent to windows when the mouse is over it. Hence, when the mouse leaves the button window, you will not get this message.Why can't you use WM_MOUSEMOVE for both highlighting and de-highlighting? If the new mouse position is over the button, highlight it, and if it's not on the button, de-highlight it
One option I often use is to design a button as a simple bitmap in my parent window, instead of a window by it's own. This way, the parent can catch when the mouse is outside of the button rectangle. However, you still have the problem of when a user moves the mouse quickly out of the parent window so even the parent doesn't get the message (this can happen quite easily).
The other alternative is to call SetCapture, but I believe this will mess up your keyboard input too.
Take your pick.
--Chorus
Last edited by chorus; 08-16-2002 at 01:41 PM.