How do I know when a mouse leaves my window when WM_MOUSELEAVE sometimes does not work?

I have a problem with TrackMouseEventand WM_MOUSELEAVE. I invoke TrackMouseEventin my application when the mouse is above my window in WM_SETCURSORand handlers WM_NCHITTEST. The problem is that if I pull the mouse out of my window very quickly, I won’t get it WM_MOUSELEAVEat all.

I am sure that I am using it correctly, because normal, slow movements will create WM_MOUSELEAVE. This only happens when the mouse moves too fast to prevent it from being generated. The problem is, how should I detect this? My application is not always in the foreground, so I'm not sure what SetCapturewill do what I need.

+3
source share
3

, WM_NCMOUSELEAVE .

: , , , TrackMouseEvent. , , MOUSELEAVE. , / ?

+1

, TrackMouseEvent . , . ( MFC)

void OnNotifyMouseLeave()
{
    // Mouse is gone
}

void OnMouseMove(UINT nFlags, CPoint point) 
{
    if ( m_uTimerId == 0 )
        m_uTimerId = SetTimer( MOUSELEAVE, 250, NULL );

    ...
}

void OnTimer( UINT_PTR nIDEvent ) 
{
    if ( nIDEvent == MOUSELEAVE )
    {
        POINT pt;
        RECT rect;
        GetCursorPos( &pt );
        GetWindowRect( &rect );
        if ( !PtInRect( &rect, pt ) )
        {   OnNotifyMouseLeave();
            if ( m_uTimerId != 0 )
            {   KillTimer( m_uTimerId );
                m_uTimerId = 0;
            }
        }
    }

    ...
}
+1

MouseLeave . SetCapture - , . , , , .

0

All Articles