2 Attachment(s)
Strange problem with simple scroll bar
I have a dialog that contains a scroll bar (SB_CTL) that doesn't give the expected behavior. The first clue is that the size of the thumb button is wrong (too large) for the range/page proportions.
It is initialized to a range of 0 to 112, with a page size of 48.
Code:
vsi.nMin = 0;
vsi.nMax = 112;
vsi.nPage = 48;
vsi.nPos = 0;
When I grab the thumb, the position will go from 0 to 65, and no higher.
If click in the 'page down' area, it will go to 96, and no higher.
If I use the 'line up' and 'line down' buttons, it will go the full range 0 to 112, but the thumb position stops early. If the position is at 112 and I click on the thumb (at the bottom of the bar), the position immediately jumps to 65.
My experiments have yielded no joy, so I have distilled a minimum length test case, and I hope someone can please tell me why this code isn't working right. Using WinXP-SP3, VC++ 8.
1 Attachment(s)
Re: Strange problem with simple scroll bar
I have found a way to get the results I expect, but I'm puzzled as to whether this is the usual way a scroll bar needs to be handled. I've never had this issue before, and I've used scroll bars many times. Or maybe I'm just getting feebleminded in my old age :(.
Initialization values:
Code:
#define DESIREDRANGE 112
#define PAGESIZ 48
vsi.nMin = 0;
vsi.nMax = DESIREDRANGE + PAGESIZ - 1;
vsi.nPage = PAGESIZ;
vsi.nPos = 0;
Handling the messages:
Code:
case WM_VSCROLL:
if ((HWND)lParam == hWvscrl)
{
switch (LOWORD(wParam))
{
case SB_LINEDOWN:
vsi.nPos++;
break;
case SB_LINEUP:
vsi.nPos--;
break;
case SB_PAGEDOWN:
vsi.nPos += PAGESIZ;
break;
case SB_PAGEUP:
vsi.nPos -= PAGESIZ;
break;
case SB_THUMBTRACK:
vsi.nPos = HIWORD(wParam);
break;
}
if (vsi.nPos > DESIREDRANGE) vsi.nPos = DESIREDRANGE;
if (vsi.nPos < vsi.nMin) vsi.nPos = vsi.nMin;
vsi.fMask = SIF_POS;
SetScrollInfo(hWvscrl, SB_CTL, &vsi, true);
}