对话中有一个picture控件,用来显示一bmp,我想实现picture控件的拖动,但由于picture属于CStatic,只有BN_CLICKED消息,所以我从CStatic中派生了CMyStatic类来响应WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE消息,消息处理函数中实现:
void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_mousedown=TRUE;
CStatic::OnLButtonDown(nFlags, point);
}void CMyStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default if(m_mousedown)
{
CPoint point1;
point1=point;
ClientToScreen(&point1);
CRect rect1;
GetWindowRect(&rect1);
MoveWindow(point1.x,point1.y,rect1.Width(),rect1.Height()); } CStatic::OnMouseMove(nFlags, point);
}
void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_mousedown=FALSE;
CStatic::OnLButtonUp(nFlags, point);
}
我的问题是:
MoveWindow(point1.x,point1.y,rect1.Width(),rect1.Height())移动picture控件的位置总也不对,感觉每次移动距离过大,超出了鼠标移动距离好几倍,不知是何原因?请大虾帮忙!
void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_mousedown=TRUE;
CStatic::OnLButtonDown(nFlags, point);
}void CMyStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default if(m_mousedown)
{
CPoint point1;
point1=point;
ClientToScreen(&point1);
CRect rect1;
GetWindowRect(&rect1);
MoveWindow(point1.x,point1.y,rect1.Width(),rect1.Height()); } CStatic::OnMouseMove(nFlags, point);
}
void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_mousedown=FALSE;
CStatic::OnLButtonUp(nFlags, point);
}
我的问题是:
MoveWindow(point1.x,point1.y,rect1.Width(),rect1.Height())移动picture控件的位置总也不对,感觉每次移动距离过大,超出了鼠标移动距离好几倍,不知是何原因?请大虾帮忙!
你试试DPtoLP、LPtoDP
{
CRect rect1;
GetWindowRect(&rect1);
ClientToScreen(&rect1); //<<--映射到屏幕
m_pParentWnd->ScreenToClient(&rect1);// <<-- 映射到父窗口
MoveWindow(&rect1);
}