(一),新建一个单文档工程HtmlCtrl,视图类基于CFormView(其它视图也行)。
(二),在#include <afxwin.h>前,加一行代码#define _WIN32_WINNT 0x0400
(三),在CHtmlCtrlView中增加一个成员变量:bool m_bMouseOver,并在构造函数中赋初值为false。
(四),手动增加WM_MOUSEMOVE和WM_MOUSELEAVE的响应函数。
//{{AFX_MSG(CCKeyEgView) afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam); //}}AFX_MSG //{{AFX_MSG_MAP(CCKeyEgView) ON_WM_MOUSEMOVE() ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave) //}}AFX_MSG_MAP void CHtmlCtrlView::OnMouseMove(UINT nFlags, CPoint point) { if(!m_bMouseOver) { TRACE(_T("Mouse enter/n")); m_bMouseOver = TRUE; TRACKMOUSEEVENT tme; tme.cbSize = sizeof(tme); tme.dwFlags = TME_HOVER | TME_LEAVE; tme.hwndTrack = m_hWnd; tme.dwHoverTime = HOVER_DEFAULT; ::TrackMouseEvent(&tme); } CFormView::OnMouseMove(nFlags, point); } LRESULT CHtmlCtrlView::OnMouseLeave(WPARAM wParam, LPARAM lParam) { TRACE(_T("Mouse Leave!/n")); m_bMouseOver = FALSE; return 0; }