OnMouseLeave

21 02 2008

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;
}
Advertisement

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s




%d bloggers like this: