stopping the mouse leaving my window

  • Follow


I have a custom control, and, when i have mouse capture, i dont want the
mouse to be able to leave my window (until i elease the capture).

Heres my code, the out of bounds check works fine, but the mouse can still
be moved out of the window !

Please tell me what im doing so very wrongly:

BOOL CFontDesignGrid::PreTranslateMessage(MSG* pMsg)
{
   if(pMsg->message == WM_MOUSEMOVE)
  {
      CPoint point(pMsg->lParam);
      CRect WndRect;
      this->GetClientRect(WndRect);
      if(
            (point.x < 0)
            ||(point.x > WndRect.Width())
            ||(point.y < 0)
            ||(point.y > WndRect.Height())
      )
      {
            TRACE("out of bounds\n");
            // remove messages:
            MSG Msg;
            PeekMessage(&Msg, this->m_hWnd, WM_MOUSEMOVE, WM_MOUSEMOVE,
PM_REMOVE);
            return TRUE;          // DONT allow the mouse movment!
            }
      }


0
Reply joey 8/2/2003 2:04:21 AM

ClipCursor(). Set it when you set capture, and clear it (set the clipping rectangle to
NULL) when you do ReleaseCapture.
					joe

On Sat, 2 Aug 2003 03:04:21 +0100, "joey" <MSforum1@---I-DONT-LIKE-SPAM---Kybert.co.uk>
wrote:

>I have a custom control, and, when i have mouse capture, i dont want the
>mouse to be able to leave my window (until i elease the capture).
>
>Heres my code, the out of bounds check works fine, but the mouse can still
>be moved out of the window !
>
>Please tell me what im doing so very wrongly:
>
>BOOL CFontDesignGrid::PreTranslateMessage(MSG* pMsg)
>{
>   if(pMsg->message == WM_MOUSEMOVE)
>  {
>      CPoint point(pMsg->lParam);
>      CRect WndRect;
>      this->GetClientRect(WndRect);
>      if(
>            (point.x < 0)
>            ||(point.x > WndRect.Width())
>            ||(point.y < 0)
>            ||(point.y > WndRect.Height())
>      )
>      {
>            TRACE("out of bounds\n");
>            // remove messages:
>            MSG Msg;
>            PeekMessage(&Msg, this->m_hWnd, WM_MOUSEMOVE, WM_MOUSEMOVE,
>PM_REMOVE);
>            return TRUE;          // DONT allow the mouse movment!
>            }
>      }
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
Reply newcomer (15983) 8/2/2003 12:52:57 AM


1 Replies
137 Views

(page loaded in 0.079 seconds)


Reply: