Re: How to calculate REAL text extent.cx

From: Michael (NOSPAMmao_at_vnet.net)
Date: 02/27/04


Date: Fri, 27 Feb 2004 11:42:16 -0500

I have an ocx with a textbox (non-window) so all I get is a rect area. The
OnDraw() controls displaying the text. I'm trying to size the rect area when
the font point size changes. The TEXTMETRIC gives enough information to size
vertical (tmHeight,tmExternalLeading,tmInternalLeading) but the
tmAveCharWidth and tmMaxCharWidth don't seem to be accurate enough to allow
me to modify the size so that the string fits horizontally within the box.

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:hhht30lmh43n6ebhj057iu631c91amueqi@4ax.com...
> Also, when you say "too short", what are you measuring against? For
example, if you are
> using it to determine the size of a control, remember that you have to
allow for the
> borders of the control and any text offsets inside the control.
> joe
>
> On Fri, 27 Feb 2004 11:08:01 +1100, "Jase"
<jshelley@spamblock.enersol.com.au> wrote:
>
> >"Michael" <NOSPAMmao@vnet.net> wrote in message
> >news:ete6DQM$DHA.2180@TK2MSFTNGP09.phx.gbl...
> >> Anyone know how to calculate the x extent of a string? I've tried
> >> GetTextExtent() and the width is short. GetCharABCWidths() returns the
> >same
> >> width as GetTextExtent(). I'm trying to adjust the rectangle to fit
around
> >> the text dynamically. I'm using TEXTMETRIC to get the y extent which
work
> >> well enough but the tm.tmAveCharWidth is too little and the
> >> tm.tmMaxCharWidth is tooo much. I need something that is juuuuuuuust
> >right.
> >> Thanks
> >>
> >
> >GetTextExtent has always worked for me. Perhaps:
> >1. Your text includes tab chars, in which case you need to use
> >GetTabbedTextExtent(...)
> >2. You haven't selected the font into the dc before calling
> >GetTextExtent(...)
> >
> >Hope that helps.
> >
> >Jase
> >
>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm



Relevant Pages

  • Re: Default font in dialog property pages
    ... Static text controls are the ones I most often change the font of; ... nice-looking headings (bold, large, centered types of headings). ... Each control IS a separate window, ...
    (microsoft.public.vc.mfc)
  • Re: variable pagelenght
    ... font 'control' was provided with Epson TMU receipt printers. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Moving controls programatially
    ... also down loaded the font that you suggested just in case I need it. ... (I know I need to iterate though the controls, but how do I get to the one I ... Also I am having no success with moving the control left or right. ... expressions can do a lot so you mightbe able to ...
    (microsoft.public.access.formscoding)
  • Re: Font Stock Property Persistance
    ... Is using an ActiveX control in the ActiveX container considered to be run ... When using the font stock property in the ActiveX ... When in a MFC dialog, it doesn't crash for me, but the font does not ... control's Visual Studio project settings to launch Visual Studio for ...
    (microsoft.public.vc.atl)
  • Re: Tip of the Day enigma
    ... but smaller than any other significant control in the dialog ... The grey area painted is not related to any object in the template. ... I was coming to the conclusion that the term 'bounding rectangle' had ... > and doing some arithmetic based on the default system font size. ...
    (microsoft.public.vc.mfc)