Valhalla Legends Forums Archive | C/C++ Programming | Writing To a Richedit

AuthorMessageTime
H0CKEY
Could I get some help. I want to send text to my richedit window on my dialog. COuld someone show me how thsi would be accomplished. thank you
January 14, 2004, 1:56 PM
Skywing
The simple way is to set the selection to the bottom of the window, and then replace it with the text that you want to add.

See EM_EXSETESEL and EM_REPLACESEL. You can use the EM_SETCHARFORMAT message to control how the text looks.
January 14, 2004, 2:58 PM
Okee
Sorry for bringing back old topics, but it's probably better than creating repeated ones.

I'm using EM_SETSEL, and adding text to my RichEdit. On msdn it says if the wParam is -1, then all selected text will be deselected. Well, I'm setting wParam to -1, and it's not deselecting my text! Anyone know why or have this happen also?

[code]
void AddText(HWND hRichEdit, char *szStatic, ...)
{
char szTextToAdd[2048] = "";
va_list vaArg;
va_start(vaArg, szStatic);
vsprintf(szTextToAdd, szStatic, vaArg);
va_end(vaArg);

SendMessage(hRichEdit, EM_SETSEL, -1, -1);
SendMessage(hRichEdit, EM_REPLACESEL, FALSE, (LPARAM)szTextToAdd);
SendMessage(hRichEdit, EM_SETSEL, -1, 0);
}
[/code]
December 17, 2004, 4:32 AM
UserLoser.
[quote author=Okee link=topic=4716.msg92678#msg92678 date=1103257924]
Sorry for bringing back old topics, but it's probably better than creating repeated ones.

I'm using EM_SETSEL, and adding text to my RichEdit. On msdn it says if the wParam is -1, then all selected text will be deselected. Well, I'm setting wParam to -1, and it's not deselecting my text! Anyone know why or have this happen also?
[/quote]

You could use EM_EXSETSEL (RichEdit specific, and perhaps better since you're using a RichEdit window) instead:

[code]
    CHARRANGE CharRange = {-1, -1};
    SendMessage(WindowHandle, EM_EXSETSEL, 0, (LPARAM)&CharRange);
    SendMessage(WindowHandle, EM_REPLACESEL, FALSE, (LPARAM)Text);
[/code]

Or, what happens if you remove the line:
[code]
SendMessage(hRichEdit, EM_SETSEL, -1, 0);
[/code]
December 17, 2004, 4:45 AM
Okee
[code]

void AddText(HWND hRichEdit, char *szStatic, ...)
{
char szTextToAdd[2048] = "";
va_list vaArg;
va_start(vaArg, szStatic);
vsprintf(szTextToAdd, szStatic, vaArg);
va_end(vaArg);

CHARRANGE CharRange = {-1, -1};
SendMessage(hRichEdit, EM_EXSETSEL, 0, (LPARAM)&CharRange);
SendMessage(hRichEdit, EM_REPLACESEL, FALSE, (LPARAM)szTextToAdd);
}
[/code]

I was using this method before I switched to the less-specific EM_EXSETSEL. It still results in selected text, even after it has replaced the selected text. There needs to be a EM_DESELECTALLTEXT or something. :-P Anyone know why this is happening?
December 17, 2004, 5:14 AM

Search