首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

OnMouseMove 怎么判断鼠标移动到按钮上的

2012-02-25 
OnMouseMove 如何判断鼠标移动到按钮上的?如题[解决办法]void CGameClientDlg::OnMouseMove(UINT nFlags,

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
}

热点排行