checking if mouse is over a window

This is a discussion on checking if mouse is over a window within the Windows Programming forums, part of the Platform Specific Boards category; is there any way to be notified possibly my message that the mouse is over a new window (even child) ...

  1. #1
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125

    checking if mouse is over a window

    is there any way to be notified possibly my message that the mouse is over a new window (even child) and tell you what window it is. Im not talking about if the window has mouse capture or input focus but if the mouse even passes over another window or child window to which the mouse is currently in?
    Thanx in Advance
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    no SetCapture? hmmmm.... I'm thinking Hook. definitely. you have to do a System wide hook and monitor WM_MOUSEMOVEs. What do you think? maybe somebody knows of an easier way?
    always looking, make an offer. get me out of this place.

  3. #3
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    i dont know about a hook im actually only checking if the mouse goes over one of my programs child windows. Also i just wondered if there was an easier way then manually checking with mouse coords.
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    but what's the actual purpose? to get a mouseaway kind of event? if so, I would definitely use SetCapture. Then you just hit test it and release capture when your mouse is not in the window. I get the idea that's not the purpose though.

    If they are child windows for your app though you could always handle WM_MOUSEMOVE in every wndproc. Update a handle or something that tells what window was the last to be moused-over
    always looking, make an offer. get me out of this place.

  5. #5
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    no i just need to know what window was last moused over in child windows of my app, like buttons
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    well then every wndproc just needs to handle the WM_MOUSEMOVE and update some value that says "HEY, the last window moused-over was me!"
    always looking, make an offer. get me out of this place.

  7. #7
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    but child windows like buttons can't handle thier own wndproc or messages
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  8. #8
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    Ahh... well you could subclass the wndproc for them but I don't suggest that. What are you trying to do? have mouseover for your buttons? Have you ever tried Windowless buttons? Meaning just draw them yourself and handle hit detection and clicks yourself. Then you can do all that stuff in the one window callback. of course you could subclass the wndproc. *shivers*
    always looking, make an offer. get me out of this place.

  9. #9
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    no its simpler then that i just want to know when the button has a mouse over it
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  10. #10
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    subclass the button wndproc. It's not too tough.

    GetWindowLong with the GWL_WNDPROC gives you a pointer to the control's callback

    SetWindowLong with the GWL_WNDPROC lets you insert your own. Then your subclassed callback needs to handle the WM_MOUSEMOVE and at the bottom it should call the original one that you got in the first step.

    On WM_DESTROY you need to set it back with SetWindowLong again.
    always looking, make an offer. get me out of this place.

  11. #11
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    before I do that is there a way to find if a pair of coords is within a rect struct, or just 4 other coods thatway I could just check when the mouse movesif the mouse coords are in thye buttons coords.
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  12. #12
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    uh I cant get it too work can I have an example
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  13. #13
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    Code:
    BOOL HitTest(RECT *rect, POINT *pt)
       {
       return pt->x > rect->left &&
                  pt->x < rect->right &&
                  pt->y > rect->top &&
                  pt->y < rect->bottom;
       }
    I'll give you a subclassing example if the hit test doesn't work for you. but it should
    always looking, make an offer. get me out of this place.

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Or use

    PtInRect()

    (takes a point and a rect struct)

    you make need ClientToScreen() or ScreenToClient()
    Last edited by novacain; 08-02-2002 at 07:23 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  15. #15
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    The coord checking worked great thanx everyone for sticking with my question
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 02:22 PM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

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