In 2003, Raymond Chen published a long series of articles about scrolling in Win32. Unfortunately, the wheel scrolling technique has a subtle bug: if the window height is less than 3 lines (more precisely, less than the scroll delta, which has a default value of 3), several lines will be skipped when scrolling.
As you can see, one line (about the Tumturn tree :) is missing. A better program will never scroll the window by more than one page for one rotation of the wheel. Change these lines:
if(uScroll == WHEEL_PAGESCROLL) {
uScroll = g_cLinesPerPage;
}
to the following ones:
if(uScroll > g_cLinesPerPage) {
uScroll = g_cLinesPerPage;
}
WHEEL_PAGESCROLL is defined as UINT_MAX, so the modified code will handle WHEEL_PAGESCROLL as well as the small window height.
The code for handling sub-detent wheel mice also was simplified in the program below. Such beasts currently do not exist, so instead of writing the sophisticated code for line-by-line scrolling with them, you could scroll by 3 lines as with usual mouse. The function is simpler this way.
Download the full code (MSVC++ 2005 or Pelles C, 6 KB zip archive)
2 comments
What does the user have to do to get WHEEL_PAGESCROLL sent?