• Welcome to Valhalla Legends Archive.
 

Writing To a Richedit

Started by H0CKEY, January 14, 2004, 07:56 AM

Previous topic - Next topic

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

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.

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?


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

UserLoser.

Quote from: Okee on December 16, 2004, 10:32 PM
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?

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


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


Or, what happens if you remove the line:

SendMessage(hRichEdit, EM_SETSEL, -1, 0);

Okee



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


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?