string width in pixels

  • Thread starter Thread starter Rajko
  • Start date Start date
R

Rajko

How can I mesure string width in pixels?
I found : Graphics.MeasureString Method.
It is in System.Drawing namespace.
I need to use it in static library.
Well, class Graphics does not have any constructors (at least in my MSDN).

So, if I can't use System::Drawing::Graphics::MeasureString in static lib,
and Graphics *g = new System::Drawing::Graphics() does not work.
How can I call MeasureString Method?

Or if someone knows how to mesure lets say CString width in pixels.
Or auto size CStatic to it's content (runtime implementation).

Thanks, Rajko.
 
Rajko said:
How can I mesure string width in pixels?
I found : Graphics.MeasureString Method.
It is in System.Drawing namespace.
I need to use it in static library.
Well, class Graphics does not have any constructors (at least in my MSDN).

So, if I can't use System::Drawing::Graphics::MeasureString in static lib,
and Graphics *g = new System::Drawing::Graphics() does not work.
How can I call MeasureString Method?

Or if someone knows how to mesure lets say CString width in pixels.
Or auto size CStatic to it's content (runtime implementation).

Thanks, Rajko.

Use Win32 DrawText w/ the DT_CALCRECT flag.
 
Thx, Julie.
I used CDC.GetTextExtent(str).
GetTextExtent and DrawText do the same thing.
They don't calculate str correctly.
In case string is "IIIIIIIIIIIII" they do OK, but when string is "mmmmmm"
they calculate "mmmmmm " ????
MSDN says thet they don't care for forn kerning and that may be it but i
wont to create dialog control dinamicaliy and need more accurate function.

Thanks, Rajko.
 
Back
Top