Archived

This topic is now archived and is closed to further replies.

Spider_In_A_Web

ref:: tutorial 13 a question

Recommended Posts

I was wondering if it is possible to calculate the length of the string drawn to screen in tutorial 13?? This is done in tutorial 14, but i would like to be able to do it with the text produced in number 13!! Thanks for your help on this and other questions i have asked!! Chrs

Share this post


Link to post
Share on other sites
Ist the length of the string on screen i require not the amount of characters in it!!

in tutorial 14, this is done using a loop that gets the distance from each character to the next, but I cannot work out how to do this with the text from method 13!!

is it possible, or does anyone have any suggestions!

Share this post


Link to post
Share on other sites
Only way would be to guess the pixel width of each character of a font and see which width works best.

Or load up the font from the windows directory take a snapshot of it and count the length in pixels manually in Paint

Share this post


Link to post
Share on other sites
Alright, to get the length of a string in a window using a windows font, you can use the win32 function GetTextExtentExPoint(), which can also return the positions at which you need to break the string in order to get it to fit within the boundaries that you want. Look it up on MSDN, and it tells you exactly how to use it. If you''re going to be using multiple fonts, then you''ll have to keep the HFONT for each font that you create so that you can select it again before you make this call, as it will use whatever font is currently selected.

jw

Share this post


Link to post
Share on other sites