OnMouseMove 如何判断鼠标移动到按钮上的?
如题
[解决办法]
void CGameClientDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(point.x> 777 && point.x <799 && point.y> 1 && point.y <22)//此区域是关闭键
{
m_mb_close.state = BUTTON_STATE_STOP;
}
CDialog::OnMouseMove(nFlags, point);
}
[解决办法]
BOOL CWnd::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg-> hwnd== m_button.m_hWnd &&pMsg-> message==WM_MOUSEMOVE)
{
int pos=0;
}
return CWnd::PreTranslateMessage(pMsg);
}
[解决办法]
// Get the current mouse position
CPoint pointMouse;
GetCursorPos(&pointMouse);
// Transform into client coordinates
ScreenToClient(&pointMouse);
CRect rect;
yourButtom.GetClientRect(&rect);
if (rect.PtInRect(point))
{
// mouse is over button
}