How to insert text into an advanced edit control in Win32, retaining any previous formatting

I am developing a chat application in win32. Currently, I dynamically allocate memory for advanced editing of controls, add a new line, and set new text using SetWindowText.

When a message arrives with certain keywords, the application colors the line and adds it to the chat window. Everything is fine. The problem occurs when you receive the following message - any previous formatting is lost!

How to solve this problem?

+3
source share
1 answer

, . -, . , :

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);
+4

All Articles