我将CAboutDlg上加了一个static的控件,里面是邮件地址,我想当鼠标经过控件的时候,鼠标样式变成小手void CAboutDlg::OnStaticEmail()
{
// TODO: Add your control notification handler code here
ShellExecute(0, NULL, "mailto:[email protected]", NULL,NULL, SW_NORMAL);
}#ifndef IDC_HAND
#define IDC_HAND MAKEINTRESOURCE(32649)
#endifvoid CAboutDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetDlgItem(IDC_STATIC_EMAIL)->GetWindowRect(&rect);
if (rect.PtInRect(point))
{
SetCursor(LoadCursor(NULL,IDC_HAND));//这一句不执行
}
else
{
SetCursor(LoadCursor(NULL,IDC_HELP));//这句执行
} CDialog::OnMouseMove(nFlags, point);
}
我换过好几种样式,就是if里的不执行,else的执行,到底怎么回事啊??唉,急死人了
{
// TODO: Add your control notification handler code here
ShellExecute(0, NULL, "mailto:[email protected]", NULL,NULL, SW_NORMAL);
}#ifndef IDC_HAND
#define IDC_HAND MAKEINTRESOURCE(32649)
#endifvoid CAboutDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetDlgItem(IDC_STATIC_EMAIL)->GetWindowRect(&rect);
if (rect.PtInRect(point))
{
SetCursor(LoadCursor(NULL,IDC_HAND));//这一句不执行
}
else
{
SetCursor(LoadCursor(NULL,IDC_HELP));//这句执行
} CDialog::OnMouseMove(nFlags, point);
}
我换过好几种样式,就是if里的不执行,else的执行,到底怎么回事啊??唉,急死人了
要用 ScreenToClient 转一下 就可以了
MapWindowPoints(GetSafeHwnd(),GetDlgItem(IDC_STATIC_EMAIL)->GetSafeHwnd(),&pt,1);
if (rect.PtInRect(pt))
{
SetCursor(LoadCursor(NULL,IDC_HAND));//这一句不执行
}
else
{
SetCursor(LoadCursor(NULL,IDC_HELP));//这句执行
}
GetDlgItem(IDC_STATIC44)->GetWindowRect(&rect);
ClientToScreen(&point);
if (rect.PtInRect(point))
{
SetCursor(LoadCursor(NULL,IDC_HAND));//这一句不执行
}
else
{
SetCursor(LoadCursor(NULL,IDC_HELP));//这句执行
}
你上面是在对话框中处理的,但是你在对话框中移动鼠标,当鼠标移到static控件上时,消息就已经发给这个控件了,对话框就收不到消息了。
我前段时间写了一个,LZ可以参见http://blog.kingsamchen.com/archives/517
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_MOUSEMOVE)
{
CRect rect;
GetDlgItem(IDC_VER)->GetWindowRect(&rect);
if (rect.PtInRect(pMsg->pt))
{
SetCursor(LoadCursor(NULL,IDC_WAIT));//这一句不执行
}
else
{
SetCursor(LoadCursor(NULL,IDC_HELP));//这句执行
}
}
return CDialog::PreTranslateMessage(pMsg);
}
当你将鼠标移到static上之后,此时消息就不再发给你的对话框了,而是发给了static控件,所以,此时对话框的void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point) 函数根本就不会被触发。