You can initialize the current value and range of a scroll bar to non-default values by sending the SBCDATA structure with class-specific data for a call to WinCreateWindow:
#define ID_SCROLL_BAR 1
SBCDATA sbcd;
HWND hwndScroll,hwndClient;
/* Set up scroll-bar control data. */
sbcd.posFirst = 200;
sbcd.posLast = 400;
sbcd.posThumb = 300;
/* Create the scroll bar. */
hwndScroll = WinCreateWindow(hwndClient,
WC_SCROLLBAR,
(PSZ) NULL,
SBS_VERT | WS_VISIBLE,
10, 10,
20, 100,
hwndClient,
HWND_TOP,
ID_SCROLL_BAR,
&sbcd, /* Class-specific data */
NULL);
You can adjust a scroll-bar value and range by sending it an SBM_SETSCROLLBAR
message:
/* Set the scroll-bar value and range. */
WinSendMsg(hwndScroll, SBM_SETSCROLLBAR,
(MPARAM)300,
MPFROM2SHORT(200, 400));
You can read a scroll-bar value by sending it an SBM_QUERYPOS message:
USHORT usSliderPos;
/* Read the scroll-bar value. */
usSliderPos = (USHORT) WinSendMsg(hwndScroll,
SBM_QUERYPOS, (MPARAM) NULL, (MPARAM) NULL);
Similarly, you can set a scroll-bar value by sending an SBM_SETPOS message:
/* Set the vertical scroll-bar value. */
WinSendMsg(hwndScroll, SBM_SETPOS, (MPARAM)300, (MPARAM) NULL);
You can read a scroll-bar range by sending it an SBM_QUERYRANGE message:
MRESULT mr;
USHORT usMinimum, usMaximum;
/* Read the vertical scroll-bar range. */
mr = WinSendMsg(hwndScroll, SBM_QUERYRANGE, (MPARAM) NULL, (MPARAM) NULL);
usMinimum = SHORT1FROMMR(mr); /* minimum in the low word */
usMaximum = SHORT2FROMMR(mr); /* maximum in the high word */