#### Archived

This topic is now archived and is closed to further replies.

# Win32 RichEdit

## Recommended Posts

MatrixCubed    199
I''ve come across this, and duplicated the problem by accident, but I am unsure of the best way to rectify the problem. When I create a RichEdit control and add some text -- using SetWindowText() -- it seems that the control tends to auto-select or highlight the string that I have passed to it. I''ve tried using EM_SETSEL to set the selection to before the first character in the string, but this doesn''t seem to be an elegant solution (nor does it even work). I''ve checked through the Win32 documentation, but I''m not really sure what to be looking for; this seems to be a symptom of something else, like a creation flag (autoselect?) or ... I don''t know, I can''t find anything on this behavior. Any help is appreciated! MatrixCubed
http://MatrixCubed.cjb.net

##### Share on other sites
Oluseyi    2112
What are your creation flags? Why are you using SetWindowText rather than some _ADDSTRING-type message?

##### Share on other sites
MatrixCubed    199
Pretty standard:

      CONTROL         "",IDC_DisplayBox,"RICHEDIT",ES_MULTILINE |                     ES_AUTOVSCROLL | ES_AUTOHSCROLL | WS_TABSTOP,0,0,225,120

As for an "_ADDSTRING"-type message, no such thing exists for rich edit controls. The proper means of "adding" text to it is maintaining your own data, then pointing the control to it using SetWindowText().

I suppose I should mention, too, that I am solely using Win32, not MFC.

MatrixCubed
http://MatrixCubed.cjb.net

##### Share on other sites
siim04    122
Hi!

I suggest replacing setwindowtext with streamin and a callback function (I may supply you with some of my own code about that). You also said that setsel did not work. It should work - check, whether you have placed setsel after setwindowtext and whether you have set the correct parameters.

Siim Karus

##### Share on other sites
siim04    122
To remove selection call:
SendMessage(pRichEditWindow/*pointer to richedit controls window*/,EM_SETSEL,-1,0);

If it desn't work, let me know.

Adding a string in RichEditControl (or a window) is like this:

EDITSTREAM esIn;
PARAFORMAT pf;

FORMATRANGE pfr;
CHARRANGE chr;

esIn.dwError = 0;
//callback for sending text to richedit

SendMessage(pRichEditWindow/*pointer to richedit controls window*/,EM_SETSEL,nWhereTo,nWhereTo );
SendMessage(pRichEdit,EM_STREAMIN,SF_TEXT|SFF_SELECTION,esIn);
//replaces selection text (or adds if selection is 0 bytes long)

Siim Karus

[edited by - siim04 on June 18, 2002 6:21:30 AM]