I’m learning Windows programming, there’s something about scroll bar’s scroll range and page size I don’t understand.
Based On http://msdn.microsoft.com/en-us/library/bb787527.aspx,
MaxScrollPos = MaxRangeValue - (PageSize - 1)
But why? I think it’s better if
MaxScrollPos = MaxRangeValue - PageSize
If I want to display an bitmap whose height is 2000px, and the client height is 600px, It’s natural to set scroll range to [0, 2000], and page size to 600. When the scroll position is 0, the top of the bitmap is displayed; when the scroll position is 1400, the bottom of the bitmap is displayed. But If I do so, I’m able to set the scroll position to 2000 – (600 – 1) = 1401. What does position 1401 mean if 1400 should display the bottom? If “MaxScrollPos” did equal “MaxRangeValue – PageSize”, everything will work perfectly. Now I have to set the scroll range to [0, 1999] to avoid the problem. I think it’s unnatural. So, is there anyone who can explain this?
The range from 0 to 1999 covers 2000 values. It’s a zero-based index, whereas your pixel size count starts from 1.