How to 'manually' calculate the listbox thumb position relative to the item top index?
How do windows calculate the top index relative to the scrollbar thumb position?
Example, when the thumb is at:
- y17, then the top index is 0
- y25, top index is 1
- y32, top index is 2
- etc
I'm working on creating/customizing a custom list box where each row can have a different height.
I found it easy to create a separate control to 'mimic' the scrollbar than try to customize the Listbox built-in scrollbar.
A draft:
The problem is: whenever a new item is added to the list box I need to recalculate all this information of top index/thumb position again because these values changes according to the number of items/height, and this information is needed to 'mimic' the built-in Listbox scrollbar.
How I'm getting this info: a loop that iterates all Listbox items:
1- WM_VSCROLL
SendMessage
with WM_VSCROLL
and SB_LINEDOWN
to scroll one line down, and move between the indexes.
2- GetScrollBarInfo
to retrieve the thumb y position.
3- LB_GETTOPINDEX
to retrieve the top index relative to the current thumb position.
But this loop (1-2-3) process takes a lot of time.
Does someone know if there's any 'formula' to calculate this information?
I mean, when the thumb is at y, the top index is x;
Or if there's a 'faster' option than looping all indexes as I'm doing.