// Example of how to override the default range of 0-1000
// of a CREATE CONTROL SCROLLBAR.

// set some constants
// NOTE: the difference between the MIN and MAX cannot exceed 32767
#define MAXRANGE1		10		// Maximum value for scrollbar1
#define MINRANGE1		2		// Minimum value for scrollbar1  
#define MAXRANGE2		500		// Maximum value for scrollbar2
#define MINRANGE2		-150	// Minimum value for scrollbar2  
#define SB_CTL 			2		// scroll bar flag for DLL functions

set procedure to scrl

// declare functions contained in the Windows DLL USER.EXE
declare pfunc SetScrollRange returning integer in dll user.exe
declare pfunc SetScrollPos returning integer in dll user.exe

// current position of thumbwheel, initally set to the minimum
nScrlVal1 = MINRANGE1
nScrlVal2 = MINRANGE2

// create the scrollbars
@ 1,30 say 'Scroll Bar 1'
create control scrollbar 'Scroll1' at 2,30 size 1,20 save to nScrlVal1 horizontal step 2 valid ScrlValid1()
@ 4,33 say 'Scroll Bar 2'
create control scrollbar 'Scroll2' at 4,30 size 20,2 save to nScrlVal2 step 50 valid ScrlValid2()

// get the handle of the scrollbar
hScroll1 = hwnd('Scroll1')
hScroll2 = hwnd('Scroll2')

// set the scrollbar range; make sure to CAST the parameters with toint()
SetScrollRange (toint(hScroll1), toint(SB_CTL), toint(MINRANGE1), toint(MAXRANGE1), .F.)
SetScrollRange (toint(hScroll2), toint(SB_CTL), toint(MINRANGE2), toint(MAXRANGE2), .F.)

// set the initial thumbwheel position
// necessary if the minimum value starts at a negative value
SetScrollPos (toint(hScroll1), toint(SB_CTL), toint(MINRANGE1), .T.)
SetScrollPos (toint(hScroll2), toint(SB_CTL), toint(MINRANGE2), .T.)

// print the initial values
@ 0,0
? 'Scrollbar 1: ', alltrim(str(nScrlVal1))
? 'Scrollbar 2: ', alltrim(str(nScrlVal2))

// Check Event Loop: exits when user hits ESC
do while lastkey() <> 27
	myevent = chkevent()
	do while myevent = -1
		myevent = chkevent()
	enddo
enddo

// valid function for scrollbar1
function ScrlValid1()
	// check if the user tried to go past the maximum value
	if nScrlVal1 > MAXRANGE1
		nScrlVal1 = MAXRANGE1
	endif
		
	// check if the user tried to go past the minimum value
	if nScrlVal1 < MINRANGE1
		nScrlVal1 = MINRANGE1
	endif
	
	// set the thumbwheel position
	SetScrollPos (toint(hScroll1), toint(SB_CTL), toint(nScrlVal1), .T.)

	? 'Scrollbar 1: ', alltrim(str(nScrlVal1))
return .t.

// valid function for scrollbar2
function ScrlValid2()
	// check if the user tried to go past the maximum value
	if nScrlVal2 > MAXRANGE2
		nScrlVal2 = MAXRANGE2
	endif
		
	// check if the user tried to go past the minimum value
	if nScrlVal2 < MINRANGE2
		nScrlVal2 = MINRANGE2
	endif
	
	// set the thumbwheel position
	SetScrollPos (toint(hScroll2), toint(SB_CTL), toint(nScrlVal2), .T.)

	? 'Scrollbar 2: ', alltrim(str(nScrlVal2))
return .t.
