开发者

How to insert text to rich edit control in Win32 while preserving any previous formatting

开发者 https://www.devze.com 2023-03-11 11:10 出处:网络
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.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号