The Old New Thing

Scrollbars bart 6 – The wheel

The mouse wheel is tricky because the mouse wheel UI guidelines indicate that you should scroll by a user-specified amount for each "click" of the mouse, where one click is mouse units (called a "detent"). There are two subtle points about the above requirement: First, that the amount of scrolling is a ...

Keyboard accessibility for scrollbars

Note that so far, the scrollbar is accessible only with the mouse. Our next step is to add keyboard access to the scrollbar. Fortunately, this is not all that difficult. We merely map some keystrokes to equivalent scrollbar actions. Note that this doesn't make our sample program fully accessible; this ...

Answer to previous exercise on proportional scrollbars

If you look at the WM_VSCROLL message, you'll see that the scroll position is a 16-bit value. So if the number of entries is more then 65535, you won't be able to use the scroll thumb to get to the ones at the end. Try it: Change the value of g_cItems to 100000 and watch what happens. The fix is to ignore the passed to the message and ...

Scrollbars, part 4: Adding a proportional scrollbar

To obtain a proportional scrollbar, you need to tell Windows the minimum and maximum values covered by the scrollbar, the current scrollbar position, and the size of the scrollbar thumb (called the "page size"). One annoyance of the way scrollbars are set up is that the maximum value is attainable. This ...

Answer to yesterday's exercise

iMin is the lowest-index element which intersects the paint rectangle, so a simple truncating division produces the desired index. The formula for iMax can be interpreted two ways. One is that it is the roundup of the first invisible line. Recall the rectangles are exclusive of the endpoint...

Scrollbars, part 3: Optimizing the paint cycle

Observe that we paint all 100 lines in our paint handler, even though most of them aren't visible. This is a problem if there are a large number of items, or if painting an item is time-consuming. So instead, we optimize our paint cycle so as to paint only the elements which intersect the...

Scrollbars, part 2

Managing scrollbars is not hard in principle. The basic idea is not that difficult, but there are a lot of small details that need to be ironed out. If you don't get the details just right, your program will feel odd in a strange way that you often can't pinpoint, much like a subtle background hum that ...

The scratch program

Occasionally, there is need to illustrate a point with a full program. To avoid reproducing the boring parts of the program, let's agree on using the following template for our sample programs. For expository purposes, I won't use a C++ class. I'll just keep all my variables global. In a real program, of course, instance data would be ...