0

I've been messing around with UI Automation and Scrolling. I found that in notepad if you take the bounding rectangle of the scrollable window, subtract out the size of any scrollbar bounding rectangles, it scrolls perfectly. However, trying the same thing against ISpy++, which aligns the top treeview item perfectly on each scroll even when there may be one or two pixels of the next item in the view at the bottom.

The problem with that is it reports the scroll amount requested was set. Say the view was 6.384914% and you do all the math to calculate where you scroll the view to the next window, say it came out to 24.382102 (completely made up number), so you scroll there, but it really didn't because it aligned the top item which otherwise would be missing a few pixels based on height of window. You read back where scrolling decided to set it and it says it was 24.382102 (note that when the scroll actually moves a full item it does report a different final scroll position and so can be calculated out).

What would solve the above is if we knew the actual bounding rectangle of the view that represents the 6.384914% so that those extra pixels wouldn't be considered part of the view, when you move to the next page, you're now align to where the next page would actually start. In this case of the tree, the bounding rectangle would be aligned to all items that fit plus the final spacing (or that could be part of the top of the view).

I wanted to scroll and get the data perfectly without any overlaps (except on final page of course, but that could be calculated out when you have the proper aligned boundaries that matches scrolling) or extra spacing.

Is there a way to do that, that I'm missing?

TIA!!

user3161924
  • 1,849
  • 18
  • 33
  • Have you checked [`HorizontalViewSize`](https://learn.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currenthorizontalviewsize) and [`VerticalViewSize`](https://learn.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currentverticalviewsize)? For understanding your issue correctly, could you show snapshots like what you get and what you expect? And steps about how do we reproduce this issue. – Rita Han Jul 27 '20 at 03:12
  • Those sizes are a percentage of the total size of data that can be scrolled (it is the view area you see on screen). So you have to take 100% minus that to get the scroll range, then you have to figure which page you want and convert that to the scroll range. It was a pain to come up with the formula, but it works. The issue is when the tree view aligns top item, it doesn't adjust scroll position which means the view bounding rectangle is not windowssize-scrollbarsize, it's slightly less, but there is no way to get it. We need to know the bounding rectangle the ViewSize value represents. – user3161924 Jul 27 '20 at 03:37
  • Also, i really doubt the feature exists, while adding in the future would be nice, it doesn't help me now. I'll have to assume there may be overlap and have to deal with it which isn't ideal. – user3161924 Jul 27 '20 at 06:43
  • Is this issue specified to TreeView or can it be also be reproduced by other control like ListView? Could you check [this thread](https://stackoverflow.com/questions/62708112/win32-listview-iconview-top-offset) to see if it is the same issue with yours? – Rita Han Jul 28 '20 at 02:37

0 Answers0