The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Rainstorm on October 05, 2007, 03:27:33 PM

Title: Avg Character width question
Post by: Rainstorm on October 05, 2007, 03:27:33 PM
hi.

the question is regarding an example drom the platformSDK (using keyboard input)

Quote// Calculate the maximum width of a line
           
            dwLineLen = dwClientX - dwCharX;

dwClientX  is the width of the client area
dwCharX   is the average text width

so how does that calculation give you the line length ?
line length would be the width of the client area itself right ?
& dwCharX is just like the width of 1 character or something.

ty

~~

Title: Re: Avg Character width question
Post by: Tedd on October 05, 2007, 03:42:27 PM
That line doesn't seem to make much sense :dazzled:

For any font, you can get information including the average character width (usually it's just the width of the character 'x').
Given the average character width you can find out how wide N characters would be (avgCharWidth * numChars), or the number of characters that will fit into a specific width (clientWidth / avgCharWidth) -- with the division truncating (ignore the remainder.)
Monospace fonts have all characters the same width, but for variable width fonts it provides a quick guess which is usually close enough.
Title: Re: Avg Character width question
Post by: Rainstorm on October 05, 2007, 04:13:16 PM
hi Tedd,

yah what yuo said makes sense....
The excerpt is from the last example in   the 'Using Keyboard Input' section
Windows User Interface-->User Input-->Keyboard Input->Keyboard Input Overviews-->Using Keyboard Input

Thanks!