Detect when mouse over a control

This is a discussion on Detect when mouse over a control within the Windows Programming forums, part of the Platform Specific Boards category; Could somebody please show me an example code how i can detect if the mouse is over my button or ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    69

    Detect when mouse over a control

    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.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    You can trap the mouse movement in each of the controls that you wish to use it by subclassing it...
    zMan

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    16
    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

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Try putting this together...
    Attached Files Attached Files
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    To catch this, you'll need to install a timer that checks if the mouse is still there
    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.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    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."

  7. #7
    Registered User
    Join Date
    Aug 2002
    Posts
    16
    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
    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.

    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  2. mouse control
    By explosive in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2004, 06:54 AM
  3. Mouse 'control' prob in OpenGL
    By gazsux in forum Game Programming
    Replies: 5
    Last Post: 04-17-2003, 10:00 AM
  4. Replies: 6
    Last Post: 07-27-2002, 01:24 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21