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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Scrollbars ??

Scrollbars ??

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 3 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.
  • 0 Offline
    0 Offline
    0v3rloader
    wrote on last edited by
    #1

    Hi, I shouldn't have initiated another thread really, but I think that, although the previous question is similar to this new one, this one I have stumbled across with is a bit different. The question is I have shown a vertical scrollbar in a custom control (by calling ShowScrollBar, but, although I keep it updated by notifying it of the mins and maxes and the current position, it is behaving as if it was still expecting to be initiated: the bar doesn't work; you can't drag the bar as it is always in the same position; . . . Are there any steps I am missing out here? Thank you very much for your time. David

    E J 2 Replies Last reply
    0
    • 0 0v3rloader

      Hi, I shouldn't have initiated another thread really, but I think that, although the previous question is similar to this new one, this one I have stumbled across with is a bit different. The question is I have shown a vertical scrollbar in a custom control (by calling ShowScrollBar, but, although I keep it updated by notifying it of the mins and maxes and the current position, it is behaving as if it was still expecting to be initiated: the bar doesn't work; you can't drag the bar as it is always in the same position; . . . Are there any steps I am missing out here? Thank you very much for your time. David

      E Offline
      E Offline
      Edwin Brunner
      wrote on last edited by
      #2

      Please give us a code fragment, so we might see, what's your problem. In general, scrollbars do their work.

      1 Reply Last reply
      0
      • 0 0v3rloader

        Hi, I shouldn't have initiated another thread really, but I think that, although the previous question is similar to this new one, this one I have stumbled across with is a bit different. The question is I have shown a vertical scrollbar in a custom control (by calling ShowScrollBar, but, although I keep it updated by notifying it of the mins and maxes and the current position, it is behaving as if it was still expecting to be initiated: the bar doesn't work; you can't drag the bar as it is always in the same position; . . . Are there any steps I am missing out here? Thank you very much for your time. David

        J Offline
        J Offline
        Jesper Knudsen
        wrote on last edited by
        #3

        Hi You may have to add ON_WM_VSCROLL() to your message map and implement the function, maybe something like this, which works for me. Think I stole some of it from mfc's own CScrollView, take a look here too. Don't know why this doesn't work automatically inside mfc. I feel like (by calling SetScrollPos()) I'm telling the scrollbar something it actually already knows. Well mfc is not alway intuitive, and always trying to figure out "why" will make you go nuts :confused:. Who knows why scrolling works like this, am I completely out of track here? - Jesper void EPropListCtrl::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar ) { int nNewPos = -1; int sp = GetScrollPos(SB_VERT); if( nSBCode==SB_THUMBPOSITION || nSBCode==SB_THUMBTRACK ) { nNewPos = nPos; } else if( nSBCode==SB_LINEUP ) { sp -= 5; nNewPos = sp; } else if( nSBCode==SB_LINEDOWN ) { sp+=5; nNewPos = sp; } else if( nSBCode==SB_PAGEUP ) { sp-=20; nNewPos = sp; } else if( nSBCode==SB_PAGEDOWN ) { sp+=20; nNewPos = sp; } if( nNewPos >= 0 ) { SetScrollPos( SB_VERT , nNewPos ); Invalidate(); } }

        0 1 Reply Last reply
        0
        • J Jesper Knudsen

          Hi You may have to add ON_WM_VSCROLL() to your message map and implement the function, maybe something like this, which works for me. Think I stole some of it from mfc's own CScrollView, take a look here too. Don't know why this doesn't work automatically inside mfc. I feel like (by calling SetScrollPos()) I'm telling the scrollbar something it actually already knows. Well mfc is not alway intuitive, and always trying to figure out "why" will make you go nuts :confused:. Who knows why scrolling works like this, am I completely out of track here? - Jesper void EPropListCtrl::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar ) { int nNewPos = -1; int sp = GetScrollPos(SB_VERT); if( nSBCode==SB_THUMBPOSITION || nSBCode==SB_THUMBTRACK ) { nNewPos = nPos; } else if( nSBCode==SB_LINEUP ) { sp -= 5; nNewPos = sp; } else if( nSBCode==SB_LINEDOWN ) { sp+=5; nNewPos = sp; } else if( nSBCode==SB_PAGEUP ) { sp-=20; nNewPos = sp; } else if( nSBCode==SB_PAGEDOWN ) { sp+=20; nNewPos = sp; } if( nNewPos >= 0 ) { SetScrollPos( SB_VERT , nNewPos ); Invalidate(); } }

          0 Offline
          0 Offline
          0v3rloader
          wrote on last edited by
          #4

          This is very distressing! I have been taking a look at some sites and apparently there is much more to scrollbars than it actually seems to be at first. Do you know if there is a (more) straight forward approach on how to [manually] program scrollbars? David BTW: Thanks a lot for the code -- it was very helpful.

          J 1 Reply Last reply
          0
          • 0 0v3rloader

            This is very distressing! I have been taking a look at some sites and apparently there is much more to scrollbars than it actually seems to be at first. Do you know if there is a (more) straight forward approach on how to [manually] program scrollbars? David BTW: Thanks a lot for the code -- it was very helpful.

            J Offline
            J Offline
            Jesper Knudsen
            wrote on last edited by
            #5

            I have around five years of mfc programming behind be, and one thing I've learned is that there is no such a thing as "forward approach". But as I mentioned before, looking at mfc's own scroll code may help you a great deal. And btw, don't forget, you'll have to set the dc's viewportorg yourself before drawing in your OnPaint() function. This is what makes the control scroll its contents. something like this (please forgive me if this doesn't compile, it's straight out of my mind..) void SomeControl::OnPaint() { // let the scrollbars move dc's viewportorg CPaintDC dc(this); int orgx = GetScrollPos(SB_HORZ); int orgy = GetScrollPos(SB_VERT); dc.SetViewPortOrg(-orgx,-orgy); // then draw the actual control dc.MoveTo(0,0); dc.LineTo(100,100); } Good luck - Jesper

            0 1 Reply Last reply
            0
            • J Jesper Knudsen

              I have around five years of mfc programming behind be, and one thing I've learned is that there is no such a thing as "forward approach". But as I mentioned before, looking at mfc's own scroll code may help you a great deal. And btw, don't forget, you'll have to set the dc's viewportorg yourself before drawing in your OnPaint() function. This is what makes the control scroll its contents. something like this (please forgive me if this doesn't compile, it's straight out of my mind..) void SomeControl::OnPaint() { // let the scrollbars move dc's viewportorg CPaintDC dc(this); int orgx = GetScrollPos(SB_HORZ); int orgy = GetScrollPos(SB_VERT); dc.SetViewPortOrg(-orgx,-orgy); // then draw the actual control dc.MoveTo(0,0); dc.LineTo(100,100); } Good luck - Jesper

              0 Offline
              0 Offline
              0v3rloader
              wrote on last edited by
              #6

              Thanks a lot Jesper. Like I said in my previous post, you have been very helpful. I only hope I may be of assistance to you in the future. Cheers, David

              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