strange error...

Started by
2 comments, last by BouncePup 21 years, 9 months ago
I''m using the following code to insert & format text into a Subclassed richedit ctrl.. ********** int iTotalLen = GetWindowTextLength(); SetSel(iTotalLen, iTotalLen); ReplaceSel(szData); int iStartPos = iTotalLen; CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_COLOR | CFM_UNDERLINE | CFM_BOLD; cf.dwEffects = (unsigned long) ~( CFE_AUTOCOLOR | CFE_UNDERLINE | CFE_BOLD); cf.crTextColor = crColor; int iEndPos = GetWindowTextLength(); SetSel(iStartPos, iEndPos); SetSelectionCharFormat(cf); HideSelection(TRUE, FALSE); LineScroll(1); ********** Yet this seems to happen when I insert data into the control using the above code: -=IMG=- www.dyaus.com/weird1.jpg Any ideas on either how to fix it or how to do it properly? Regards, Nate Strandberg
"Always forgive your enemies, nothing annoys them more.."
Advertisement
I am assuming that your crColor is red. If that is the case then the problem seems to me to be that you are adding the text, but the SetSel calls are not selecting the just written text properly and you end up only coloring a portion of each string. I don''t really know why the start and end positions wouldn''t be correct, but maybe GetWindowTextLength is not correctly counting the carriage return/line feed pairs at the end of each string. Just a guess.
Yeah.. If I take out the new line ("\n") it colorizes it fine..

Any idea how to properly count everything?

-Nate
"Always forgive your enemies, nothing annoys them more.."
You can tell how many carrage return/line feed pairs you have by taking the line count (GetLineCount()) and either adding or subtracting that from the GetWindowTextLength() depending on whether or not it is counting them or not. My guess is that GetWindowTextLength() is counting CR/LF pairs, but SetSel is not. Maybe it is the other way around. Anyway, counting the lines may help.

This topic is closed to new replies.

Advertisement