Posted on 2007-01-12 15:41
梁海泉 阅读(2039)
评论(0) 编辑 收藏 引用
添加鼠标进入和离开事件
作者:梁海泉
因为鼠标的进入和离开不是一个标准的window事件,所以要手动添加代码,先建一个OnMouseMove事件,再手动添加OnMouseLeave和OnMouseHover事件,分别在OnMouseMove事件的下面。
/*************************************************************************/
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnMouseHover(WPARAM wParam, LPARAM lParam);
/*************************************************************************/
BEGIN_MESSAGE_MAP(CTButton, CButton)
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
END_MESSAGE_MAP()
/*************************************************************************/
void
CTButton::OnMouseMove(UINT nFlags, CPoint point)
{
TRACKMOUSEEVENT tme;
tme.cbSize
=
sizeof
(tme);
tme.hwndTrack
=
m_hWnd;
tme.dwFlags
=
TME_LEAVE
|
TME_HOVER;
tme.dwHoverTime
=
1
;
::TrackMouseEvent(
&
tme);
CButton::OnMouseMove(nFlags, point);
}
LRESULT CTButton::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
SetWindowText(
"
鼠标离开
"
);
return
0
;
}
LRESULT CTButton::OnMouseHover(WPARAM wParam, LPARAM lParam)
{
SetWindowText(
"
鼠标进来
"
);
return
0
;
}