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?
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 ...
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
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
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:
However, instead of using a scroll bar, I would strongly suggest you use a trackbar control.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; }
As far as I know, you haven't offended anybody, some questions just slip by.
Thanks, but in my haste I've written my own slider control.
MSVC++ 6.0