Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Scrollbar move with mouse ?

Scrollbar move with mouse ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mesajflaviu
    wrote on last edited by
    #1

    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 ?

    S M 2 Replies Last reply
    0
    • M mesajflaviu

      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 ?

      S Offline
      S Offline
      Sauro Viti
      wrote on last edited by
      #2

      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 and WM_LBUTTONUP to do it. Basically, in the WM_LBUTTONDOWN message handler you have to set a flag that mean dragging and save the cursor location and the scrollbars position; in the WM_LBUTTONUP you have to reset the dragging flag. Finally, in the WM_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.

      M 1 Reply Last reply
      0
      • S Sauro Viti

        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 and WM_LBUTTONUP to do it. Basically, in the WM_LBUTTONDOWN message handler you have to set a flag that mean dragging and save the cursor location and the scrollbars position; in the WM_LBUTTONUP you have to reset the dragging flag. Finally, in the WM_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.

        M Offline
        M Offline
        mesajflaviu
        wrote on last edited by
        #3

        Thank you Viti . I develop this [^] project , that have implement all things that you said ... but I don't know how effectively move scrollbars considering mouse position on client area ... do you know some sample code ?

        S 1 Reply Last reply
        0
        • M mesajflaviu

          Thank you Viti . I develop this [^] project , that have implement all things that you said ... but I don't know how effectively move scrollbars considering mouse position on client area ... do you know some sample code ?

          S Offline
          S Offline
          Sauro Viti
          wrote on last edited by
          #4

          Try this article[^] from Microsoft, and refer to the IntelliMouse panning implementation.

          M 1 Reply Last reply
          0
          • S Sauro Viti

            Try this article[^] from Microsoft, and refer to the IntelliMouse panning implementation.

            M Offline
            M Offline
            mesajflaviu
            wrote on last edited by
            #5

            Thanks again Viti , is not like what I want but from this sample I learn very much !!!!

            1 Reply Last reply
            0
            • M mesajflaviu

              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 ?

              M Offline
              M Offline
              mesajflaviu
              wrote on last edited by
              #6

              I did it :

              void CDragSheetView::OnLButtonDown(UINT nFlags, CPoint point)
              {
              // TODO: Add your message handler code here and/or call default

              m\_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 default

              if(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);
              

              }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups