我正在使用以下例程来通过用户的鼠标操作选择矩形区域。但它目前正在基于可见视图而不是整个可滚动视图中选择区域。我想知道是否有任何方法可以在可见视图中获得(0,0)的偏移值。那就是我想在可见区域中对应于(0,0)的整个可滚动区域中找到(x,y)。
更新:找到GetScrollPosition()。
// COpenCVTestView message handlers
void COpenCVTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
anchor = endpoint = point;
CClientDC dc(this);
dc.DrawFocusRect(&CRect(anchor.x, anchor.y, endpoint.x, endpoint.y));// very small rectangle
SetCapture();
}
void COpenCVTestView::OnLButtonUp(UINT nFlags, CPoint point)
{
if(GetCapture() != NULL)
{ /* banding */
COpenCVTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CClientDC dc(this);
dc.DrawFocusRect(&CRect(anchor.x, anchor.y, endpoint.x, endpoint.y));
pDoc->m_recSelection = CRect(anchor.x, anchor.y, point.x, point.y);
ReleaseCapture();
InvalidateRect(&(pDoc->m_recSelection));
} /* banding */
}
void COpenCVTestView::OnMouseMove(UINT nFlags, CPoint point)
{
if(GetCapture() != NULL)
{ /* rubber band */
CClientDC dc(this);
dc.DrawFocusRect(&CRect(anchor.x, anchor.y, endpoint.x, endpoint.y));
endpoint = point;
dc.DrawFocusRect(&CRect(anchor.x, anchor.y, endpoint.x, endpoint.y));
} /* rubber band */
}