两种方法:
1、派生一个CButton类,然后重载OnSetCursor函数,在里面
使用SetCursor函数设置鼠标指针。
然后删除
return CButton::OnSetCursor(pWnd, nHITTest, message);
改成
return TRUE;
例如:
BOOL CMyButton::OnSetCursor(CWnd* pWnd, UINT nHITTest, UINT message)
{
::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND)));
return TRUE;
}
2、直接在程序里,响应WM_MOUSEMOVE消息,在里面判断鼠标指针是否指到了按钮上,是的话就用SetCursor函数设置鼠标指针,离开再设回以前的指针
void CbpmDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRect adbanerRect;
CRect btnSelectPathRect;
CRect btnStartRect;
m_GifPic.GetWindowRect(&adbanerRect);
m_btnSelectPath.GetWindowRect(&btnSelectPathRect);
m_btnStart.GetWindowRect(&btnStartRect);
//如何鼠标在广告位置或按钮上,改变鼠标指针
if(adbanerRect.PtInRect(point)||btnSelectPathRect.PtInRect(point)||btnStartRect.PtInRect(point))
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
CDialog::OnMouseMove(nFlags, point);
}
光有上面一个函数还是不行的,还需要重载CWnd类的虚拟函数PreTranslateMessage()
BOOL CbpmDlg::PreTranslateMessage(MSG *pMsg)
{
if(pMsg->message == WM_MOUSEMOVE)
{
OnMouseMove(pMsg->wParam,pMsg->pt);
}
return CDialog::PreTranslateMessage(pMsg);
}
pretranslatemessage()作用和使用方法:点击打开链接