I found a workaround for it, that works at least for me. When I first tried to save/backup and restoring the old CHARFORMAT
, I did it without specifying CFM_COLOR
for CHARFORMAT cf_old
. Now I use:
SendMessage(con, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf_old);
cf_old.dwMask = CFM_COLOR;
SendMessage(con, EM_SETSEL, -1, -1);
SendMessage(con, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
SendMessage(con, EM_REPLACESEL, FALSE, (LPARAM)text);
SendMessage(con, EM_SETSEL, -1, -1);
SendMessage(con, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf_old);
It somehow explains why my first try didn't work. It seems that everytime you add something to the RichEdit the CHARFORMAT of the first char before the caret is used.