您的位置:首页 > 其它

根据鼠标起点和落点判断鼠标操作

2016-03-18 13:53 656 查看
1.需要声明对话框的消息解析函数

virtual BOOL PreTranslateMessage(MSG* pMsg);


2.对鼠标按键进行判断,当前以鼠标左键作为例子:

BOOL CDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if(WM_LBUTTONDOWN== pMsg->message)
{
if (m_bLeftButtonDown==FALSE)
{
int xPos = LOWORD(pMsg->lParam);
int yPos = HIWORD(pMsg->lParam);

m_LastPoint.x=xPos;
m_LastPoint.y=yPos;
::ClientToScreen(pMsg->hwnd,&m_LastPoint);
m_bLeftButtonDown=TRUE;
}
}else if (WM_LBUTTONUP==pMsg->message)
{
if (m_bLeftButtonDown)
{
int xPos = LOWORD(pMsg->lParam);
int yPos = HIWORD(pMsg->lParam);
m_CrrentPoint.x=xPos;
m_CrrentPoint.y=yPos;
::ClientToScreen(pMsg->hwnd,&m_CrrentPoint);
m_bLeftButtonDown=FALSE;
DoYouThings();//处理你想处理的动作
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: