Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Measure String Width and Height in GDI+

353 views
Skip to first unread message

Saitama

unread,
Sep 5, 2008, 8:17:00 AM9/5/08
to
Hi,

Assume that 1 logical unit = 1 device unit,

and I have "Gdiplus::Font( lpwszFontName, (REAL)iFontSize )",

Then how can I get the size of a text with that font without creating
Graphics object? It doesn't need to be very exact size.

Because, MeasureString() method of GDI+ requires Graphics object to be
created first. That method is member of Graphics object.

BobF

unread,
Sep 5, 2008, 8:34:48 AM9/5/08
to

An option if you have a DC:

http://msdn.microsoft.com/en-us/library/a6x7y2a4(VS.80).aspx


Check out DT_CALCRECT in the remarks. By calling this with the text you
want measured, you should get the results you're after.

Mark Salsbery [MVP]

unread,
Sep 5, 2008, 11:47:04 AM9/5/08
to
"Saitama" <Sai...@discussions.microsoft.com> wrote in message
news:07092CAA-67C6-41A9...@microsoft.com...

> Hi,
>
> Assume that 1 logical unit = 1 device unit,
>
> and I have "Gdiplus::Font( lpwszFontName, (REAL)iFontSize )",
>
> Then how can I get the size of a text with that font without creating
> Graphics object? It doesn't need to be very exact size.


This is a device-dependent calculation. You can't do a device-dependent
calculation without a device.

You can "Assume that 1 logical unit = 1 device unit" but the system cannot.

Why are you against creating a Graphics object?

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

Saitama

unread,
Sep 5, 2008, 10:29:01 PM9/5/08
to
Mark you're right, it is the device dependent calculation.
I just wonder if I can get the size of text only by font name and font size.

Thanks for your help!

0 new messages