在LButtonDown函数中最好添加 this->SetCapture();
同时在LButtonUP函数中添加
if (GetCapture() == this)
{
ReleaseCapture();
}
一旦在这两个函数里面添加了这两个功能,则MouseMove函数中的鼠标点坐标就可以是视口以外的坐标点。
在选中滑动视口中尤其重要。
选中 滑动代码:
//多选框
if(m_bCreateNewDevice == false && m_SysAction == DRAW_RANGE_SELECT)
{
CPoint pt = cpoint;
ClientToDoc(pt);
CRect rectTotal(0,0, wholeRect.Width(), wholeRect.Height());
if (!rectTotal.PtInRect(pt))
{
return;
}
CRect rectWnd(0, 0, 0, 0);
GetClientRect(&rectWnd);
ClientToDoc(rectWnd);
CPoint ptScroll = GetScrollPosition();
if (rectTotal.Width() > rectWnd.Width())
{
CSize szGrid;
szGrid.cx = m_iGridWidth;
szGrid.cy = m_iGridHeight;
DocToClient(szGrid);
int iMoveCap = szGrid.cx;
if ((rectWnd.right < pt.x ))
{
/*此时,鼠标向右移动,并已移出了视图*/
int iPos = GetScrollPos(SB_HORZ);
if (iPos == wholeRect.Width())
{
return;
}
ptScroll.x += iMoveCap;
ScrollToPosition(ptScroll);
Invalidate(FALSE);
ClientToDoc(szGrid);
iMoveCap = szGrid.cx;
pt.x += iMoveCap;
}
else if ( (rectWnd.left > pt.x))
{
int iPos = GetScrollPos(SB_HORZ);
/*此时,鼠标向左移动,并已移出了视图*/
ptScroll.x -= iMoveCap;
ScrollToPosition(ptScroll);
Invalidate(FALSE);
ClientToDoc(szGrid);
iMoveCap = szGrid.cx;
pt.x -= iMoveCap;
}
}
if (rectTotal.Height() > rectWnd.Height())
{
CSize szGrid;
szGrid.cx = m_iGridWidth;
szGrid.cy = m_iGridHeight;
DocToClient(szGrid);
int iMoveCap = szGrid.cy;
if ((rectWnd.bottom < pt.y))
{
/*此时,鼠标向下移动,并已移出了视图*/
ptScroll.y += iMoveCap;
ScrollToPosition(ptScroll);
Invalidate(FALSE);
ClientToDoc(szGrid);
iMoveCap = szGrid.cy;
pt.y += iMoveCap;
}
else if ((rectWnd.top > pt.y))
{
/*此时,鼠标向上移动,并已移出了视图*/
ptScroll.y -= iMoveCap;
ScrollToPosition(ptScroll);
Invalidate(FALSE);
ClientToDoc(szGrid);
iMoveCap = szGrid.cy;
pt.y -= iMoveCap;
}
}
m_SelectRangeCurPoint = point;