Click here to Skip to main content
14,386,540 members
Rate this:
Please Sign up or sign in to vote.
Hi All,

I have a multi-line string need to be drawn in a rectangular area which has fixed-width and variable height. As the string being drawn in the rectangle, if a line's length exceeds the area's width, the exceeding part will be put in to a new line.

What I need is to calculate height of boundary rectangle of text area. How can i do it?

I did check GetTextExtend...() functions of CDC, but they allow to get extent of SINGLE line string only.

Please help me in this regard.

Thanks in Advance.
Quy
Posted
Updated 5-Jul-11 22:30pm
v5

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can use the CDC::DrawTextEx() function with the DT_CALCRECT flag set in nFormat and the rect you wish to draw to in lpRect.

This will expand the bottom of the rect to fit you multi line string.

Take a look at:
CDC::DrawTextEx()[^]

However IMO the better explination of this function is teh corrasponding win32 function which describes the flags better, found here:
DrawTextEx()[^]
   
Comments
quyps 6-Jul-11 21:40pm
   
Thank Rhunors, it's exactly what i'm looking for. 5*!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100