RE: (Newbie) Using built-in scrollbars - ta Dan!

new topic     » topic index » view thread      » older message » newer message

Dan,

Thanks very much for your amended code - it got me thinking and I have 
now figured out how to alter the scroll ranges as well.  

I delved into some win32 documentation and it turned out that you should 
be able to get/set built-in scrollbar attributes with the 
get/setScrollInfo functions. 

Looking in win32lib these functions exist but they have not been quite 
correctly implemented for built-in scrollbars. I extracted & fixed the 
relevant code and I attach an amended code sample below which shows the 
built-in scrollbar ranges being altered programmatically.

Do you happen to know who I should send win32lib fix requests to these 
days?

Many thanks to you and everybody else who replied to my original post

Regards,

Phil

-- scroll.exw
-- Test built-in scrollbars
-- (displays scrollbar position in window)
-- Phil Russell Nov 2001
---- with slight modification by Dan Moyer
---- and further by Phil after inspiration provided above...

without warning
include win32lib.ew

-- Create window with built-in scrollbars
constant ScrollWin =
    create( Window, "ScrollTest", 0, Default, Default, 200, 200, 
WS_SCROLLBARS )
    
    
-- Modified from win32lib.setScrollRange     
procedure setBuiltInScrollRange( integer window_id, integer scrollbar, 
integer min, integer max )

    -- set the allowable range for a scroll bar
    atom sif
    object VOID -- ***duplicated from win32lib

    -- store value ***no access to win32lib private sequence
    --window_range[ id ] = { min, max }

    -- Allocate structure
    sif = acquire_mem(0, SIZEOF_SCROLLINFO )
	
    -- store values
    store( sif, sifSize, SIZEOF_SCROLLINFO )
    store( sif, sifMask, SIF_RANGE )
    store( sif, sifMin, min )
    store( sif, sifMax, max )

    -- check for valid scrollbar option
    -- SB_VERT = vertical scrollbar
    -- SB_HORZ = horizontal scrollbar
    if scrollbar = SB_VERT or scrollbar = SB_HORZ then

	VOID = w32Func( xSetScrollInfo,
		    {   getHandle( window_id ),     -- handle
			scrollbar,                  -- scroll bar to change
			sif,                        -- pointer to structure
			0 } )                       -- redraw flag
    end if
	
    -- Free structure
    release_mem( sif )
	
end procedure

    
-- Process scroll event (as amended by Dan Moyer and further by me)
procedure onScroll_ScrollWin( integer pos)

-- show scrollbar positions
setPenPosition( ScrollWin, 1, 10 ) -- ADD THIS
wPuts(ScrollWin, "Horizontal: " & sprint(getHScrollPos( ScrollWin ))) -- 
AND THIS
setPenPosition( ScrollWin, 1, 30 )-- AND THIS
wPuts(ScrollWin, "Vertical: " & sprint(getVScrollPos( ScrollWin ))) 
--AND THIS

end procedure

procedure onOpen_ScrollWin ()

	-- *** Fool win32lib into not clipping the scrollbars
	setScrollRange(ScrollWin, 0, 999)
	
	-- *** Alter the scroll ranges
	setBuiltInScrollRange( ScrollWin, SB_VERT, 0, 500 )
	setBuiltInScrollRange( ScrollWin, SB_HORZ, 0, 20 )	

end procedure
   
-- Trap scroll event
onScroll[ScrollWin] = routine_id("onScroll_ScrollWin")   

-- Initialisation
onOpen[ScrollWin] = routine_id("onOpen_ScrollWin")

-- Hand control over to Windows
WinMain( ScrollWin, Normal )

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu