CRichEditCtrl mystery - selection, streaming and formatting
-
My problem is this: I use SetSel() and SendMessage(EM_SETCHARFORMAT, ...) to highlight stuff in the control, and it works fine when using SetWindowText() to set the contents of the control. However, when I use streaming for setting the contents, and if the selection to highlight starts at the first character position (CHARRANGE.cpMin = 0), the highlighting is applied to the entire contents of the control. Moreover, the formatting remains when I fill the control with new text, even if I don't highlight anything in the new text. Reproducable with:
// streaming callback function int nTransfer; nTransfer = _tcslen(m_pchStreamBuf); if(nTransfer > cb) nTransfer = cb; memmove(pbBuff, m_pchStreamBuf, nTransfer); *pcb = nTransfer; m_pchStreamBuf += nTransfer; return 0; // formatting CHARFORMAT2 cf; memset(&cf, 0, sizeof(cf)); cf.cbSize = sizeof(cf); cf.dwMask = CFM_COLOR | CFM_BACKCOLOR; cf.crTextColor = RGB(0x00, 0, 0); cf.crBackColor = RGB(0x00, 0xff, 0xff); m_ctrl.SetSel(0, 3); m_ctrl.SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
Anyone?