Question Details

No question body available.

Tags

c winapi scroll scrollbar

Answers (4)

April 28, 2026 Score: 2 Rep: 1,843 Quality: Low Completeness: 30%

That are suppositions that have to be confirmed with testing, by slightly modifying the code for example:

  1. In WMSIZE

The "2" looks like some sort of 1px left and right margin.

  1. In WMPAINT

Only visible lines are written: this is the y-axis formula. But the whole line is written, even invisible characters: this is the x-axis formula. And the "1" in "1 - iHorzPos" is the left 1px margin.

April 28, 2026 Score: 1 Rep: 1,408 Quality: Low Completeness: 40%

Raymond Chen's blog has a series of articles about scrollbars; you might want to check them out.

Raymond Chen's blog, "The Old New Thing," contains a wealth of useful knowledge about Windows programming and is highly recommended for everyone to read.

However, be aware that some content may be outdated. For example, with the introduction of DWM, the visible region of a window is no longer clipped by other windows.

April 28, 2026 Score: 0 Rep: 135,026 Quality: Low Completeness: 40%

Why are you reading this book? It's important from a historical, even archaeological perspective, but even in 2000 very few people used raw message pumps or raw drawing. The offsets may well be used to handle borders, something handled by dedicated APIs in later versions of Windows. Different border styles, glass, curving etc meant it was no longer possible to just assume a fixed border size. You could (had) to ask Windows what the size of scrollbars, borders etc are.

And even in the 1990s people used frameworks like MFC and later ATL to handle drawing, scrolling, borders etc instead of handling these themselves. As the component already knew its drawing area, the code didn't have to calculate offsets.

By the time Programming Windows, 6th Edition came out in 2013, such code had disappeared.

April 28, 2026 Score: 0 Rep: 1,537 Quality: Low Completeness: 20%

As another pointed out, the 1st item is almost certainly about margins. I would try it with and without the '2' and note the visual differences, if any.

The 2nd item (1 - iHorzPos) seems to be a typo -- maybe 'i' was meant for both these items, ie: (i - iVertPos) and (i - iHorzPos) but a scanner or something turned 'i' into '1'. (1 - iHorzPos) would also probably result in a negative number, casting more doubt upon its accuracy. Unless of course a negative value is needed -- this is usually rare but it happens.