Hello,
I am having difficulties with the vertical scrollbar in an application window containing a status box at the bottom. With my best effort (edited code below), the scroll arrows work correctly, but moving the scroll button to the bottom of the scrollbar stops short, leaving the bottom of my application covered by the scrollbar. Any suggestions welcome (I obviously have to add or subtract the height of the status box somewhere, but where?...)
switch (iMsg)
{
case WM_CREATE :
//create status bar (ID = 19)
hwndStatus = CreateStatusWindow (WS_CHILDWINDOW | WS_VISIBLE | CCS_BOTTOM ,
"default", hwnd, 19) ;
case WM_SIZE :
// Retrieve the dimensions of the client area
yClient = HIWORD (lParam);
// Set the vertical scrolling range and page size
yMaxScroll= yMax ;
yCurrentScroll = min(yCurrentScroll,yMaxScroll) ;
GetClientRect (hwndStatus, &rect) ;
si.cbSize = sizeof(si) ;
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS ;
si.nPage = yClient + (rect.bottom-rect.top) ;
si.nPos = yCurrentScroll ;
si.nMin = 0 ;
si.nMax = yMaxScroll ;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE) ;
// status bar
GetWindowRect (hwndStatus, &rWindow) ;
cy = rWindow.bottom - rWindow.top ;
x = 0 ;
y = yClient - cy ;
cx = xClient ;
MoveWindow (hwndStatus, x, y, cx, cy, TRUE) ;
return 0 ;
case WM_VSCROLL:
{
int yNewPos; // new position
switch (LOWORD(wParam))
{
case SB_PAGEUP:
yNewPos = yCurrentScroll - 50;
break;
case SB_PAGEDOWN:
yNewPos = yCurrentScroll + 50;
break;
case SB_LINEUP:
yNewPos = yCurrentScroll - 5;
break;
case SB_LINEDOWN:
yNewPos = yCurrentScroll + 5;
break;
case SB_THUMBPOSITION:
yNewPos = HIWORD(wParam);
break;
default:
yNewPos = yCurrentScroll;
}
// New position must be between 0 and the screen height.
GetClientRect (hwndStatus, &rect) ;
yNewPos = max(0, yNewPos);
yNewPos = min(yMaxScroll + (rect.bottom - rect.top) - yClient, yNewPos);
// Scroll if the current position is changed
if (yNewPos != yCurrentScroll)
{
bScroll = TRUE ;
hdc = GetDC (hwnd) ;
InvalidateRect (hwnd, NULL, TRUE) ;
ReleaseDC (hwnd, hdc) ;
}
yCurrentScroll = yNewPos;
yScrollPos=yCurrentScroll * fMagnify;
// Reset the scroll bar.
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = yCurrentScroll;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
I am having difficulties with the vertical scrollbar in an application window containing a status box at the bottom. With my best effort (edited code below), the scroll arrows work correctly, but moving the scroll button to the bottom of the scrollbar stops short, leaving the bottom of my application covered by the scrollbar. Any suggestions welcome (I obviously have to add or subtract the height of the status box somewhere, but where?...)
switch (iMsg)
{
case WM_CREATE :
//create status bar (ID = 19)
hwndStatus = CreateStatusWindow (WS_CHILDWINDOW | WS_VISIBLE | CCS_BOTTOM ,
"default", hwnd, 19) ;
case WM_SIZE :
// Retrieve the dimensions of the client area
yClient = HIWORD (lParam);
// Set the vertical scrolling range and page size
yMaxScroll= yMax ;
yCurrentScroll = min(yCurrentScroll,yMaxScroll) ;
GetClientRect (hwndStatus, &rect) ;
si.cbSize = sizeof(si) ;
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS ;
si.nPage = yClient + (rect.bottom-rect.top) ;
si.nPos = yCurrentScroll ;
si.nMin = 0 ;
si.nMax = yMaxScroll ;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE) ;
// status bar
GetWindowRect (hwndStatus, &rWindow) ;
cy = rWindow.bottom - rWindow.top ;
x = 0 ;
y = yClient - cy ;
cx = xClient ;
MoveWindow (hwndStatus, x, y, cx, cy, TRUE) ;
return 0 ;
case WM_VSCROLL:
{
int yNewPos; // new position
switch (LOWORD(wParam))
{
case SB_PAGEUP:
yNewPos = yCurrentScroll - 50;
break;
case SB_PAGEDOWN:
yNewPos = yCurrentScroll + 50;
break;
case SB_LINEUP:
yNewPos = yCurrentScroll - 5;
break;
case SB_LINEDOWN:
yNewPos = yCurrentScroll + 5;
break;
case SB_THUMBPOSITION:
yNewPos = HIWORD(wParam);
break;
default:
yNewPos = yCurrentScroll;
}
// New position must be between 0 and the screen height.
GetClientRect (hwndStatus, &rect) ;
yNewPos = max(0, yNewPos);
yNewPos = min(yMaxScroll + (rect.bottom - rect.top) - yClient, yNewPos);
// Scroll if the current position is changed
if (yNewPos != yCurrentScroll)
{
bScroll = TRUE ;
hdc = GetDC (hwnd) ;
InvalidateRect (hwnd, NULL, TRUE) ;
ReleaseDC (hwnd, hdc) ;
}
yCurrentScroll = yNewPos;
yScrollPos=yCurrentScroll * fMagnify;
// Reset the scroll bar.
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = yCurrentScroll;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);