News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Petzold - setting scroll bar range with SetScrollInfo

Started by bf2, September 21, 2011, 09:59:06 PM

Previous topic - Next topic

bf2

I cannot work out this line of sample code from Petzold on page 114 (SysMets3):

For horizontal scroll, he sets the nMax member of SCROLLINFO as:
si.nMax   = 2 + iMaxWidth / cxChar;

I understand the iMaxWidth / cxChar bit but cannot work out the logic of adding 2. I was thinking maybe he just added 2 to allow a bit more space, but then I saw this MSDN page with an almost identical code. So there must be a better reason for adding 2.

http://msdn.microsoft.com/en-us/library/hh298421%28v=VS.85%29.aspx

Any thoughts?
Thanks.

dedndave

i dunno about Peitzold, but i use pixels 1 to 1 for nMin, nMax, nPos values

i set nMin to 0 and leave it there all the time
if the data area is, say, 120 pixels high, i set nMax to 120
as you can see, that means nMax-nMin = 120
but, if you count possible nPos positions, there are 0 to 120, or 121 possible values   :P
this could account for 1 of the 2 value

baltoro

I read Petzold (but it was years ago), and, the one thing I liked about his book is that he explained everything so clearly.
It's got to be something really simple, but, I can't remember.
If I had to guess, I'd say that it's just the minimum increase for either space under the final line, or an adjustment in case the resultant value exactly equals the line height, so that the text display is completely visible and doesn't appear truncated.
Baltoro

jj2007

Quote from: dedndave on September 21, 2011, 10:50:33 PM
but, if you count possible nPos positions, there are 0 to 120, or 121 possible values   :P
this could account for 1 of the 2 value

The other one could be for rounding errors. Test it with a very small number, e.g. 0...3