在视图中用鼠标拖动直线控件的原理是什么?
我在视图中动态创建了一个直线控件(通过按钮控件),我想通过鼠标拖动它。
实现这个的原理是什么?
先把控件删除,然后在不停的创建。。。。
还是。。。。。
问题点数:20、回复次数:2Top
1 楼loveghb(温柔的毒药)回复于 2005-07-23 11:46:58 得分 20
晕死,如此简单的问题没人回答
直线控件响应WM_MOUSEDOWN、WM_MOUSEMOVE、WM_MOUSEUP消息,WM_MOUSEDOWN的时候设置标志,并捕获鼠标,然后WM_MOUSEMOVE的时候移动直线控件
Top
2 楼jackadandy(锋行天下)回复于 2005-07-25 09:29:24 得分 0
现在是鼠标有时能拖动控件,有时候拖动不了。怎么回事啊?
void CDisplayviewView::OnLButtonDown(UINT nFlags, CPoint point)
{
//get the position of mouse
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
if(((point.x>=rect1.left)&&(point.x<=rect1.right))&&((point.y>=rect1.top)&&(point.y<=rect1.bottom)))
{
darrow1=1;
SetCapture();
}
else
if (((point.x>=rect2.left)&&(point.x<=rect2.right))&&((point.y>=rect2.top)&&(point.y<=rect2.bottom)))
{
darrow2=1;
SetCapture();
}
}
void CDisplayviewView::OnLButtonUp(UINT nFlags, CPoint point)
{
if((darrow1==1)||(darrow2==1))
{
if (GetCapture() != this)
return; // If this window (view) didn't capture the mouse,
// then the user isn't drawing in this window.
darrow1=0;
darrow2=0;
ReleaseCapture();
}
}
void CDisplayviewView::OnMouseMove(UINT nFlags,CPoint point)
{
CRect rect;
if (GetCapture() != this)
return; // If this window (view) didn't capture the mouse,
// then the user isn't drawing in this window.
//get the position of mouse
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
if(darrow1==1)
{
rect1.left=point.x;
rect1.right=point.x+1;
dc.LPtoDP(&point);
rect.left=point.x;
rect.right=point.x+1;
rect.top=rect1.top;
rect.bottom=rect1.bottom;
p_Radio1->MoveWindow(&rect,TRUE);//movewindow用设备坐标
}
else
if(darrow2==1)
{
rect2.left=point.x;
rect2.right=point.x+1;
dc.LPtoDP(&point);
rect.left=point.x;
rect.right=point.x+1;
rect.top=rect2.top;
rect.bottom=rect2.bottom;
p_Radio2->MoveWindow(&rect,TRUE);
}
}
其中rect1,rect2为两个直线控件创建时的位置。Top




