1.添加以下变量:
public:
bool m_bMouseDown;
POINT m_ptStart;
2.在构造函数中添加以下代码
m_bMouseDown=false;
3.响应WM_MOUSEMOVE,WM_LBUTTONDOWN,WM_LBUTTONUP消息.并添加以下代码
OnMouseMove(UINT nFlags,CPoint point)
{
......
if(m_bMouseDown)
{
RECT rect;
GetWindowRect(&rect);
OffsetRect(&rect,point.x-m_ptStart.x,point.y-m_ptStart.y);
MoveWindow(&rect,true);
}
}
OnLButtonDown(UINT nFlags,CPoint point)
{
m_bMouseDown=true;
SetCapture();
m_ptStart.x=point.x;
m_ptStart.y=point.y;
}
OnLButtonUp(UINT nFlags,CPoint point)
{
m_bMouseDown=false;
ReleaseCapture();
}