MFC 中Static text 如何响应鼠标hover事件?

2024-12-05 00:51:20
推荐回答(2个)
回答1:

重载CStatic类,在鼠标入入事件中添加
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 1;
_TrackMouseEvent(&tme);
则会接收到鼠标离开事件。

BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSEMOVE,mv)
ON_MESSAGE(WM_MOUSEHOVER,mho)
ON_MESSAGE(WM_MOUSELEAVE,ml)
ON_MESSAGE(WM_MOUSEFIRST,mf)
END_MESSAGE_MAP()

回答2:

需要重写CSTATIC类!~