No announcement yet.

Detecting mouse position

  • Filter
  • Time
  • Show
Clear All
new posts

  • Detecting mouse position

    Hi, all !
    I try to place non-modal elements on console window.
    I create and register own class of windows -
    (popup, parent is a console window) and have "full" access to all messages.
    Now I imitate a work of "button", and after mouse-down I need to detect mouse-up (it's easy) and a moment, when mouse is leaving my window to do automatic "turn off".
    I have "mouse-move" event, can understand that mouse is near border (for example, position (1,1)), but not more, because mouse-move not occurs with step 1 pixel.
    Any ideas ?

  • #2
    Semen, there is no such WM_MOUSELEAVING message, so instead
    we need creativity here.

    Only suggestion is to use a timer like a watch-dog.
    1/10th of second watch-dog timer should work. Every time-out you
    can GetCursorPos(), and translate to screen coordinates and
    compare with your buttons coordinates to see if the mouse is
    still inside this controls RECT. If not the mouse must have
    left the building.

    Regards, Jules

    [This message has been edited by Jules Marchildon (edited February 04, 2000).]


    • #3
      Jules --
      nice idea, works. One problem less.



      • #4
        Another way to do it is to "capture" the mouse as soon as it enters your button area and then compare it's position as it moves with the size/location of your button, when the mouse leaves the button area then ReleaseCapture.

        That's how Microsoft does it.


        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Home of the BASIC Gurus


        • #5
          Thanks, Dave.
          I tried. Unfortunately not works. Perhaps, I do something wrong, but I think that explanation in another - a parent is a console window. First (and last) %WM_CAPTURECHANGED appears after second (!) SetCapture.