三个消息:
1、鼠标左键按下----------------WM_LBUTTONDOWN;
2、鼠标移动----------------------WM_MOUSEMOVE;
3、鼠标左键弹起----------------WM_LBUTTONUP
消息相应:
void CRobotControlDlg::OnLButtonDown(UINT nFlags, CPoint point)
{// TODO: 在此添加消息处理程序代码和/或调用默认值
SetCapture();
CRect rW;
GetWindowRect(rW);
CPoint ptW = point;
ClientToScreen(&ptW);
m_ptCursorOffset.x = ptW.x - rW.left;
m_ptCursorOffset.y = ptW.y - rW.top;
CDialogEx::OnLButtonDown(nFlags, point);
}
void CRobotControlDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if ((nFlags & MK_LBUTTON) && this == GetCapture())
{
CRect rW;
GetWindowRect(rW);
CPoint ptW = point;
ClientToScreen(&ptW);
ptW.x -= m_ptCursorOffset.x;
ptW.y -= m_ptCursorOffset.y;
::SetWindowPos(m_hWnd, 0,ptW.x,ptW.y,0,0,SWP_NOSIZE);
}
CDialogEx::OnMouseMove(nFlags, point);
}
void CRobotControlDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
ReleaseCapture();
CDialogEx::OnLButtonUp(nFlags, point);
}