The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: bf2 on September 21, 2011, 09:59:06 PM

Title: Petzold - setting scroll bar range with SetScrollInfo
Post by: bf2 on September 21, 2011, 09:59:06 PM
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.
Title: Re: Petzold - setting scroll bar range with SetScrollInfo
Post by: dedndave on September 21, 2011, 10:50:33 PM
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
Title: Re: Petzold - setting scroll bar range with SetScrollInfo
Post by: baltoro on September 22, 2011, 09:23:41 PM
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.
Title: Re: Petzold - setting scroll bar range with SetScrollInfo
Post by: jj2007 on September 22, 2011, 10:21:22 PM
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