Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I am finding an issue where in I have a Text which is longer than a single line with no spaces. This text is not displayed completely in the tool tip. It gets truncated.

I make use of CDC for the tooltip display rectangle,
C++
CDC* pDC = GetDC();
CRect rect(0, 0, 0, 0);
CString sComment = "this is a  comment bigggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg  comment  2 2 2"
    pDC->DrawText(sComment, &rect, DT_CALCRECT | DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_TOP);
int iheight = rect.Height(); // It wont return the correct rectangle height

//Output is
this is a comment biggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg

Can anyone tell me what the issue is.


Thanks,
Chethana
Posted
Updated 18-Oct-10 20:51pm
v5

1 solution

does it even compiles?

C++
virtual int DrawText(
   LPCTSTR lpszString,
   int nCount,
   LPRECT lpRect,
   UINT nFormat 
);
int DrawText(
   const CString& str,
   LPRECT lpRect,
   UINT nFormat 
);


drawtext needs a pointer to a RECT you need to use &rect in your code, but then you are using DT_CALCRECT which will return you the needed width and height of your rect, you can do a first call to DrawText to get the needed dimenions of the rect and then draw it something like:

C++
CDC* pDC = GetDC();
   CRect rect(0, 0, 0, 0);
   CString sComment = "this is a  comment bigggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg  comment  2 2 2"
       pDC->DrawText(sComment, &rect, DT_CALCRECT | DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_TOP);

       pDC->DrawText(sComment, &rect, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_TOP);
   int iheight = rect.Height(); // It wont return the correct rectangle height



that should help
 
Share this answer
 
v2
Comments
Member 7528548 19-Oct-10 1:12am    
Hi,

There was a typo with the pointer to rect. I am actually sending &rect.
I tried with your suggestion, still the tooltip gets truncated.

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