RE: Scrolling Toolbar??

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

Ron,

It isn't that much work - most of it is coping with the fact that 
win32lib doesn't seem to pass on scroll messages for child windows with 
scrollbars so you have to duplicate a little bit of code.  I have 
chucked together an example which I *think* does what you want.

HTH

Phil

<start>
include Win32Lib.ew
without warning

constant
ScrollWindow = registerw32Procedure( user32, "ScrollWindow", 
{C_LONG,C_LONG,C_LONG,C_POINTER,C_POINTER} )

constant
MainWin 	= create( Window, "Scroll test", NULL, 0.25, 0.25, 300, 200, 0 
),
ToolBar  	= create( ToolBar, "", MainWin, 0, 0, 0, 34, 0 )

-- Get client area of main window
sequence rect rect = getClientRect(MainWin)

constant
-- Size child window to client area of main window
ChildWin = create( Window, "", MainWin, 0, 1, rect[3], rect[4]-35, 
{WS_CHILD, WS_VISIBLE, WS_VSCROLL} ),
Edit1 = create( EditText, "Edit1", ChildWin, 10, 10, 150, 20, 0 ),
Edit2 = create( EditText, "Edit2", ChildWin, 10, 110, 150, 20, 0 ),
Edit3 = create( EditText, "Edit3", ChildWin, 10, 210, 150, 20, 0 )

-- Variables for holding scroll info
integer OldVPos OldVPos = 0
integer MinScroll MinScroll = 1
integer MaxScroll MaxScroll = 100
integer ScrollPage ScrollPage = 10

-- Set Child window scroll range
setWindowScrollRange(ChildWin, SB_VERT, MinScroll, MaxScroll, 
ScrollPage)

--*------------------------------------------------------*
-- onScrollEvent: Event handler for ChildWin
--*------------------------------------------------------*
procedure onScrollEvent (atom self, atom event, sequence parms)

    integer VChange, Pos, scrolltype

    -- Test for vertical scroll
	if parms[1] = WM_VSCROLL then

		scrolltype = lo_word(parms[2])
	
		if find(scrolltype, {SB_THUMBPOSITION, SB_BOTTOM,
		    				 SB_TOP, SB_LINEDOWN,
		    				 SB_LINEUP, SB_PAGEDOWN,
		    				 SB_PAGEUP} ) then		

			Pos = 0
		
			-- Get new scrollbar position depending on scroll event
			if scrolltype = SB_THUMBPOSITION then
				Pos = getVScrollPos(self)
			elsif scrolltype = SB_BOTTOM then
				Pos = MinScroll
			elsif scrolltype = SB_TOP then
				Pos = MaxScroll
			elsif scrolltype = SB_LINEUP then
				Pos = OldVPos - 1
			elsif scrolltype = SB_LINEDOWN then
				Pos = OldVPos + 1
			elsif scrolltype = SB_PAGEUP then
				Pos = OldVPos - ScrollPage
			elsif scrolltype = SB_PAGEDOWN then
				Pos = OldVPos + ScrollPage
			end if
		
			-- Clip to range
    		if Pos < MinScroll then
    			Pos = MinScroll
    		elsif Pos > MaxScroll then
    			Pos = MaxScroll
    		end if
    	
    		-- Scroll window
	    	VChange = OldVPos - Pos
	    	w32Proc( ScrollWindow, {getHandle(self),0, VChange, 0, 0} )
	    	setVScrollPos(self, Pos)
	    	OldVPos = Pos
	    end if

	end if
end procedure
setHandler(ChildWin, w32HEvent, routine_id("onScrollEvent"))

WinMain( MainWin, Normal )
<end>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu