Scrollbar move with mouse ?
-
If I have an CScrollView with few lines , rectangles and other , can I move scrollbar with mouse due the mouse is within client area ? Something like acrobat reader sheets , when the mouse cursor is hand , on OnLButtonDown mouse pointer change to 'MoveHand' cursor and OnMouseMove move scrollbars ?
-
If I have an CScrollView with few lines , rectangles and other , can I move scrollbar with mouse due the mouse is within client area ? Something like acrobat reader sheets , when the mouse cursor is hand , on OnLButtonDown mouse pointer change to 'MoveHand' cursor and OnMouseMove move scrollbars ?
Yes, you could, but you have to write all the required code: provide an "hand" mode and change the cursor when that mode is active, then handle the
WM_LBUTTONDOWN
,WM_MOUSEMOVE
andWM_LBUTTONUP
to do it. Basically, in theWM_LBUTTONDOWN
message handler you have to set a flag that mean dragging and save the cursor location and the scrollbars position; in theWM_LBUTTONUP
you have to reset the dragging flag. Finally, in theWM_MOUSEMOVE
you have to test the dragging flag, and if it is set, set the scrollbars position to obtain a shift of your view that correspond to one that the mouse has been moved. -
Yes, you could, but you have to write all the required code: provide an "hand" mode and change the cursor when that mode is active, then handle the
WM_LBUTTONDOWN
,WM_MOUSEMOVE
andWM_LBUTTONUP
to do it. Basically, in theWM_LBUTTONDOWN
message handler you have to set a flag that mean dragging and save the cursor location and the scrollbars position; in theWM_LBUTTONUP
you have to reset the dragging flag. Finally, in theWM_MOUSEMOVE
you have to test the dragging flag, and if it is set, set the scrollbars position to obtain a shift of your view that correspond to one that the mouse has been moved. -
-
Thanks again Viti , is not like what I want but from this sample I learn very much !!!!
-
If I have an CScrollView with few lines , rectangles and other , can I move scrollbar with mouse due the mouse is within client area ? Something like acrobat reader sheets , when the mouse cursor is hand , on OnLButtonDown mouse pointer change to 'MoveHand' cursor and OnMouseMove move scrollbars ?
I did it :
void CDragSheetView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call defaultm\_point = point; m\_bMouseCapture = TRUE; SetCursor(AfxGetApp()->LoadCursor(IDC\_CURSOR\_HANDMOVE)); SetCapture(); CScrollView::OnLButtonDown(nFlags, point);
}
void CDragSheetView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call defaultif(m\_bMouseCapture) { CPoint ptScroll = GetScrollPosition(); if(m\_point.x < point.x)ptScroll.x -= (point.x - m\_point.x); if(m\_point.x > point.x)ptScroll.x += (m\_point.x - point.x); if(m\_point.y < point.y)ptScroll.y -= (point.y - m\_point.y); if(m\_point.y > point.y)ptScroll.y += (m\_point.y - point.y); ScrollToPosition(ptScroll); m\_point = point; } CScrollView::OnMouseMove(nFlags, point);
}