在PreTranslateMessage中处理mouse move的消息,解决Picture Control设置notify为true之后与对话框OnMouseMove冲突的问题

来源:互联网 发布:java 1.6 32位下载 编辑:程序博客网 时间:2024/06/06 06:45

在PreTranslateMessage中处理mouse move的消息,解决Picture Control设置notify为true之后与对话框OnMouseMove冲突的问题

(注Picture Control的notify属性设置为true是为了使该控件响应点击等事件)

MFC中 监听OnMouseMove,当鼠标在Picture Control控件对应的rect区域时,更换Picture Control控件中显示的图片,但是当Picture Control控件的notify属性设置为true时,OnMouseMove中判断鼠标是否在Picture Control控件的rect区域不会响应,即这时候想实现Picture Control控件获取鼠标焦点时展示不同的视觉效果会失败。

最后解决办法是,把判断鼠标是否位于Picture Control控件的rect区域这个过程放到PreTranslateMessage处理。即如下的代码:


BOOL CExampleSixDlg::PreTranslateMessage(MSG *pMsg){//解决picture control的notify为true时与对话框mouse move时间冲突的问题。if (pMsg->message == WM_MOUSEMOVE){CRect rect;GetDlgItem(IDC_STATIC_PICTURE)->GetWindowRect(&rect);//获取控件坐标 相对于屏幕左上角CPoint  pt;GetCursorPos(&pt);//获取光标在屏幕坐标中的位置 if (rect.PtInRect(pt)){//在control区域内,提示信息,更换图片等 m_button.SetWindowText(_T("focus"));//GetDlgItem(IDC_PICTURE_TEST)->SetIcon(m_tIcon,TRUE);//加载png图片CStatic *pwd = (CStatic *)GetDlgItem(IDC_STATIC_PICTURE);CImage img;img.Load(_T("./res/test2.png"));HBITMAP hBmp = img.Detach();pwd->SetBitmap(hBmp);//加载图标iconpwd = (CStatic *)GetDlgItem(IDC_PICTURE_TEST);pwd->SetIcon(m_hIcon);}else{//不在control区域内,提示信息,更换图片等 m_button.SetWindowText(_T("focus not"));//GetDlgItem(IDC_PICTURE_TEST)->SetIcon(m_hIcon,TRUE);//加载png图片CStatic *pwd = (CStatic *)GetDlgItem(IDC_STATIC_PICTURE);CImage img;img.Load(_T("./res/test1.png"));HBITMAP hBmp = img.Detach();pwd->SetBitmap(hBmp);//加载图标iconpwd = (CStatic *)GetDlgItem(IDC_PICTURE_TEST);pwd->SetIcon(m_tIcon);}   }return CDialog::PreTranslateMessage(pMsg);}


0 0
原创粉丝点击