Scroll Bars

This is a discussion on Scroll Bars within the Windows Programming forums, part of the Platform Specific Boards category; I wish to use a scroll bar as a slider. I've worked out how to get a scrollbar on the ...

  1. #1
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368

    Scroll Bars

    I wish to use a scroll bar as a slider. I've worked out how to get a scrollbar on the screen but I can't figure out how to set its maximum and minimum values or even get it to stay where I move it.

    Can anyone help?
    MSVC++ 6.0

  2. #2
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    Wow, that's two perfectly good threads totally ignored. I must have offended someone pretty high up.

    I refuse to beleive that nobody on this board knows how to acheive what I'm looking for.
    MSVC++ 6.0

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can set the range of a scroll bar using SetScrollInfo. You respond to movement by handling the WM_HSCROLL or WM_VSCROLL messages depending on whether the scroll bar is horizontal or vertical. This is slightly complicated, as you have to manually update the position. There is an example at MSDN:
    Code:
        case WM_HSCROLL:
        {
             SCROLLINFO si     = { 0 };
             int        oldPos = 0;
    
             si.cbSize = sizeof (si);
             si.fMask  = SIF_ALL;
             GetScrollInfo (hwnd, SB_HORZ, &si);
    
             // Save the position for comparison later on
             oldPos = si.nPos;
    
             switch (LOWORD (wParam))
             {
                 // user clicked left arrow
                 case SB_LINELEFT: 
                     si.nPos -= 1;
                     break;
                  
                 // user clicked right arrow
                 case SB_LINERIGHT: 
                     si.nPos += 1;
                     break;
                  
                 // user clicked the scroll bar shaft left of the scroll box
                 case SB_PAGELEFT:
                     si.nPos -= si.nPage;
                     break;
                  
                 // user clicked the scroll bar shaft right of the scroll box
                 case SB_PAGERIGHT:
                     si.nPos += si.nPage;
                     break;
                  
                 // user dragged the scroll box
                 case SB_THUMBTRACK: 
                     si.nPos = si.nTrackPos;
                     break;
                  
                 default:
                     break;
             }
    
             // Set the position and then retrieve it.  Due to adjustments
             //   by Windows it may not be the same as the value set.
             si.fMask = SIF_POS;
             SetScrollInfo (hwnd, SB_HORZ, &si, TRUE);
             GetScrollInfo (hwnd, SB_HORZ, &si);
             
             if (si.nPos != oldPos)
             {
                 // If the position has changed, use the new value
             }
    
             return 0;
        }
    However, instead of using a scroll bar, I would strongly suggest you use a trackbar control.

    As far as I know, you haven't offended anybody, some questions just slip by.

  4. #4
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    Thanks, but in my haste I've written my own slider control.
    MSVC++ 6.0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scroll Bars Are Scrolling Me Crazy
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 03-03-2006, 01:43 PM
  2. Scroll bars
    By bigdan43 in forum C++ Programming
    Replies: 5
    Last Post: 04-19-2005, 01:05 PM
  3. Scroll Bars and Focus
    By Thantos in forum Windows Programming
    Replies: 1
    Last Post: 08-21-2003, 12:57 PM
  4. Horizontal Scroll Bars with CListBox
    By Malek in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2003, 10:58 PM
  5. Scroll Bars
    By bc17 in forum Windows Programming
    Replies: 2
    Last Post: 02-21-2003, 03:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21