How to calculate the listbox scrollbar row based on the thumb position?

Viewed 125

While searching about I found these topics by Raymond Chen position calculation in scroll bars and scrollbar series I have read all the series but I still couldn't figure out how to properly calculate it, I'm not sure if I have missed something as English is a bit difficult to me.

Based on what i read, I tried to calculate it like this:

1- Get the total height of the list box range max * row height

2- Get the scroll area listbox height - arrows - thumb height

3- How many pixels of the total height must be scrolled for each pixel of the 'scroll area' total height/scroll area

4- Resulting in the formula:

((thumb position - arrow) * pixels) / row height

To get the thumb position I have used the API GetScrollBarInfo, however, it return the thumb position in a different position than where it was, in the example below it returned 45 while it's at 40:

Example

My calc method returned 408 while the top row is 406.

I know about the APIs SetScrollInfo, GetScrollInfo and GetScrollBarInfo, however, as i mentioned they return a different position than where the thumb really was and new data (rows) is constantly added to the control im working, making not viable calling these api multiple times.

How do windows calculate the listbox top row relative to the thumb position? im looking for information to create a custom scrollbar.

0 Answers
Related