How to catch an OnMouseLeave event? Using TrackMouseEvent.
Here’s what I did:
in the CNewsBar .h
class CNewsBar : public CToolbar { protected: BOOL m_bTraceMouse; afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam); };
in the CNewsBar .cpp
BEGIN_MESSAGE_MAP(CNewsBar , CToolBar) ON_WM_MOUSEMOVE() ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave) END_MESSAGE_MAP() CNewsBar ::CNewsBar () { m_bTraceMouse = FALSE; } void CNewsBar ::OnMouseMove(UINT nFlags, CPoint point) { if (!m_bTraceMouse) { TRACKMOUSEEVENT tme; tme.cbSize = sizeof(TRACKMOUSEEVENT); tme.dwFlags = TME_LEAVE; tme.hwndTrack = this->m_hWnd; if (::_TrackMouseEvent(&tme)) { m_bTraceMouse = TRUE; } } CToolBar::OnMouseMove(nFlags, point); } LRESULT CNewsBar ::OnMouseLeave(WPARAM wParam, LPARAM lParam) { m_bTraceMouse = FALSE; return TRUE; }