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

来源:互联网 发布:淘宝客服幽默话语 编辑:程序博客网 时间:2024/04/28 15:28

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);}


0 0