VC 怎么实现对鼠标离开对话框时,事件的处理

来源:互联网 发布:uv pv seo 编辑:程序博客网 时间:2024/06/05 21:49

捕获鼠标离开对话框的事件

方法一:使用_TrackMouseEvent函数处理,对应的代码如下:
BOOL CLRCDlg::PreTranslateMessage(MSG* pMsg) {static BOOLbMouseTracking = FALSE;if(pMsg->message==WM_MOUSELEAVE)     {bMouseTracking= FALSE;AfxMessageBox("鼠标已离开对话框");}else if(pMsg->message==WM_MOUSEMOVE){if(!bMouseTracking){TRACKMOUSEEVENT   tme;   tme.cbSize=sizeof(tme);   tme.dwFlags=TME_HOVER | TME_LEAVE;   tme.dwHoverTime=50;   tme.hwndTrack=m_hWnd;   bMouseTracking = _TrackMouseEvent(&tme);}}return CDialog::PreTranslateMessage(pMsg);}

方法二:使用CRect的PtInRect函数,对应的代码如下:
BOOL CLRCDlg::PreTranslateMessage(MSG* pMsg){CRect rc;GetWindowRect(&rc);if(rc.PtInRect(pMsg->pt)){}else{AfxMessageBox("鼠标已离开对话框");}return CDialog::PreTranslateMessage(pMsg);}


0 0
原创粉丝点击