Link to home
Start Free TrialLog in
Avatar of IssacJones
IssacJones

asked on

Static Control Size

Hiya

I have an interesting problem which I hope somebody can help me with.

I have a static control in which I am displaying text.

I have been trying to get the rectangle in which the text occupies - which is going to be smaller than the static controls rectangle.

I tried to do this using the following:

CStatic* control = (CStatic*)GetDlgItem(IDC_MYSTATIC);
CString s = "This is a long message\n\nwith line breaks";
CRect rect = CRect(CPoint(0,0) ,CPoint(0,0));
CDC* pDC = control.GetDC();
pDC->DrawText( s, rect, DT_CALCRECT );

However, the dimensions of rect are not correct e.g. rect appears too wide.

Can anybody tell me what I'm doing wrong?

John
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IssacJones
IssacJones

ASKER

Thanks!
You are welcome