Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 21:30pm
v5

1 solution

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()[^]
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900