這兩個消息比較古怪,雖然你能找到他們的定義,看起來也似乎挺有用,但是卻接收不到。
如果要處理這兩個消息需要手動在WM_MOUSEMOVE消息處理函數中添加:
添加變量:
BOOL m_bTracking;
m_bTracking = FALSE;
添加消息處理函數:
afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnMouseHover(WPARAM wParam, LPARAM lParam);
用ON_MESSAGE宏進行消息映射:
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
在WM_MOUSEMOVE消息處理函數中進行處理:
void CDemo::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if (!m_bTracking) { TRACKMOUSEEVENT tme; tme.cbSize = sizeof(tme); tme.hwndTrack = m_hWnd; tme.dwFlags = TME_LEAVE | TME_HOVER; tme.dwHoverTime = 1; m_bTracking = _TrackMouseEvent(&tme); } } LRESULT CDemo::OnMouseLeave(WPARAM wParam, LPARAM lParam) { return 0; } LRESULT CDemo::OnMouseHover(WPARAM wParam, LPARAM lParam) { return 0; }