I am getting text from CEdit control. I need to imitate the same text on image. The edit control is multiline, so when I keep on typing long string the remaining part of the word goes to the next line. I am not getting at which text index in the CEdit the character goes on the next line.
So while trying to do this, I am able to insert "\r\n" if the width of line exceed the width of the rect. But the problem is if the alignment is center the the character after the inserted "\r\n" is treated as new word by the DrawText api and purpose of the above insertion of new-line character fails.
Can someone let me know, Is there some way I can know where the line is breaking in CEdit or alternative for the same.
CString strTempFormattedText(_T(""));
LONG tempTotalWidth = 0;
for(int i = 0; i < myText.GetLength(); i++) {
TCHAR tempChar = myText.GetAt(i);
tempTotalWidth += pDC->GetTextExtent(CString(tempChar), 1).cx;
if(tempTotalWidth >= rc.Width()) {
tempTotalWidth = 0;
strTempFormattedText.Append(_T("\n\r"));
}
strTempFormattedText.AppendChar(tempChar);
}
myText = strTempFormattedText;
switch(ALIGNMENT)
{
case RIGHT:
pDC->DrawText(myText, -1, rc, DT_WORDBREAK | DT_RIGHT );
break;
case CENTER:
pDC->DrawText(myText, -1, rc, DT_WORDBREAK | DT_CENTER);
break;
case LEFT:
pDC->DrawText(myText, -1, rc, DT_WORDBREAK | DT_LEFT);
break;
}
Thanks