Announcement

Collapse
No announcement yet.

mouse entering/leaving window...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • mouse entering/leaving window...

    Hello Everyone, Does anybody have any ideas on how I can detect when the mouse cursor leaves a window. I know how to detect when the mouse enters the window but leaving is another story?

    Thanks in advance...

    ------------------
    Cheers!

  • #2
    The easiest is make use of SetCapture()
    You'll still recieve mousemove msg but the windowfrompoint() shows another hWnd

    Or a timer..


    ------------------
    hellobasic

    Comment


    • #3
      Mark;

      Here is the very simple way to do it...

      Code:
       
          CASE %WM_MOUSEMOVE
              DIM bCaptured AS STATIC LONG
              'capture the mouse as soon as it enters into the window
              'do only once...
              IF bCaptured = 0 THEN
                 Call SetCapture( hWnd )
                 bCaptured = 1
              END IF
                      
              'now check if it has left the window, if so, then release
              'mouse capture...
              IF bCaptured = 1 THEN
                  Call GetCursorPos( pt )
                  Call GetWindowRect( hWnd, rc )
                  IF  PtInRect( rc, pt.x, pt.y )  = %FALSE THEN
                      'Sorry, the mouse is out for some cheese!
                      Call ReleaseCapture()
                      bCaptured = 0
                  END
              END IF
      HTH
      Regards,
      Jules

      [This message has been edited by Jules Marchildon (edited July 06, 2001).]
      Best regards
      Jules
      www.rpmarchildon.com

      Comment


      • #4
        Thanks Boys!

        That did the trick... On a side note I tried playing around the TrackMouseEvent API and it also worked but I like the SetCapture method better

        ------------------
        Cheers!

        Comment


        • #5
          Jules, I have run into another problem now. By using the SetCapture method the caption bar nolonger works and thus I cannot close the window. Any suggestions on how to fix this little problem?

          ------------------
          Cheers!

          Comment


          • #6
            Yes, that's a side effect using SDK windows.
            It seems a dialogbox msgpump doesn't bother.
            Actually, there is a topic on that in MSDN.
            For SDK i solved it by writting additional code in the msgpump to unset the capture.

            This is pretty old:

            Code:
                    Select Case Msg.Message
                    Case %WM_KEYDOWN, %WM_KEYUP
            '''
                    Case %WM_SYSCOMMAND
            
                        '// Solve a problem while Setcapture is set.
                        '// TranslateMessage will not perform ok if setcapture is used.
                        '// A temporary release of the capture is ok.
                        a = GetCapture()
                        If a Then
            
                            TranslateMessage MSG
                            SetCapture 0
                            DispatchMessage  MSG
                            SetCapture a
                            Iterate
            
                        End If
            ------------------


            [This message has been edited by Edwin Knoppert (edited July 09, 2001).]
            hellobasic

            Comment


            • #7
              I think i misunderstood but you should release the capture when no longer needed..
              If you notice you are leaving the window reset the setcapture..


              ------------------
              hellobasic

              Comment


              • #8
                Hello Edwin, I am releasing it after the cursor exits the window. I just wanted to be able to move and close the window while having the mouse capture. I may have to investigate the TrackMouseEvent once again.

                ------------------
                Cheers!

                Comment


                • #9
                  Mark;

                  Fire off a code snippet that I can compile and test. I will take a look
                  at the effects you are trying to achieve. All code is kept confidential
                  of course.

                  added later:
                  Mark, if you want to allow the caption buttons to work while SetCapture is on
                  then just exclude the height of the caption from the RECT, that will allow
                  that region to work as normal.

                  Mark;

                  Code:
                   
                      CASE %WM_MOUSEMOVE
                          DIM bCaptured AS STATIC LONG
                          'capture the mouse as soon as it enters into the window
                          'do only once...
                          IF bCaptured = 0 THEN
                             Call SetCapture( hWnd )
                             bCaptured = 1
                          END IF
                                  
                          'now check if it has left the window, if so, then release
                          'mouse capture...
                          IF bCaptured = 1 THEN
                              Call GetCursorPos( pt )
                              Call GetWindowRect( hWnd, rc )
                              '*remove the Caption area from the RECT 	
                              rc.nTop = rc.nTop + GetSystemMetrics( hWnd, %SM_CYCAPTION )
                              IF  PtInRect( rc, pt.x, pt.y )  = %FALSE THEN
                                  'Sorry, the mouse is out for some cheese!
                                  Call ReleaseCapture()
                                  bCaptured = 0
                              END
                          END IF

                  Regards,
                  Jules


                  [This message has been edited by Jules Marchildon (edited July 10, 2001).]
                  Best regards
                  Jules
                  www.rpmarchildon.com

                  Comment

                  Working...
                  X