I'm developing chat application in win32. Currently i'm dynamically allocating memory for rich edit controls text, append new line and set the new text with SetWindowText.
When a message arrives with specific keywords the app colors the line and appends it to the chat开发者_StackOverflow中文版 window. Everything's fine. Problem arises when next message is received - any previous formatting is lost!
How to solve this issue?
Ok, I've solved it. Apearantly I was replacing the text with unformated version of it. Here's how to properly append text to rich edit control:
CHARRANGE cr;
cr.cpMin = -1;
cr.cpMax = -1;
// hwnd = rich edit hwnd
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&cr);
SendMessage(hwnd, EM_REPLACESEL, 0, (LPARAM)stringtoappend);
精彩评论