Forum Discussion

MulgraveTester's avatar
MulgraveTester
Frequent Contributor
9 years ago
Solved

How can I use scroll bar methods

I have a script that uses [PageDown] to move from the top of a SysListView32 to the bottom. Unfortunately the [PageDown] key causes unwanted behaviour so I want to use the vertical scroll bar instead.

 

The SysListView32 has a CWnd_SetScrollPos method but there is no help for this and the function description shown in the object spy simply says:

"Function CWnd_SetScrollPos(Param1 as Integer, Param2 as Integer, Param3 as Integer) as Integer"

with no indication what each of the parameters are for.

 

Can you provide help on this and other scroll bar methods?

 

How else can I move the list using the vertical scroll bar?

  • What I usually do is this

     

    'Prepare to know when to stop scrolling
    'Identify an object on the top of the page/list to know that you've scrolled completely to the top
    	SET objTop = objParent.FindChild(PropArray, ValuesArray, depth)
    'Identify an object on the botton of the page/list to know that you've scrolled completely to the top
    	SET objBottom = objParent.FindChild(PropArray, ValuesArray, depth)
    
    'Scroll to the required object	
    'Find the object that we are interested in 	
    	SET objChild = objParent.FindChild(PropArray, ValuesArray, depth)
    	IF objChild.VisibleOnScreen THEN
    		'Do something with the object
    	ELSE
    		DO WHILE NOT objTop.VisibleOnScreen
    			lib_MouseScrollUp(objPage,5) 'Find a number that sufficiently scrolls for you and use scroll up or down methods as required
    			IF objChild.VisibleOnScreen THEN EXIT DO 
    		LOOP
    END IF
    
    'Functions for scrolling
    
    FUNCTION lib_MouseScrollUp(ByRef obj, ByVal count)
      obj.MouseWheel count
    END FUNCTION
    
    'OR
    
    FUNCTION lib_MouseScrollDown(ByRef obj, ByVal count)  
      obj.MouseWheel 0-count
    END FUNCTION

     

11 Replies

    • MulgraveTester's avatar
      MulgraveTester
      Frequent Contributor

      The ListView32 does not have a .Window("TScrollBar") object, so none of the help seems relevant.

       

      There are 300 items in my list object with 42 in view at any one time.

      I've found that the vScroll.Pos property is read/write so I can set the position with

         myObj.vscroll.Pos = 41

       

      This works for some values but I get an error for others

      "Failed to set position 41 for the scroll bar. 42 was set instead."

       

      There is nothing in the application that prevents me sliding the scrollbar to any position with the mouse, so now I am wondering why some values are Ok and some are not. How do I slide the scrollbar without creating errors?

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        41 probably fails if the object is not visible at that pont.

         

        (You mention there are only 42 of 300 visible)

         

        So I suspect it doesn't work if you try and point it to a non-visible item and it goes to the next available visible one.