Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Append without SetSel() or SetWindowText()

Posted on 2003-03-10
Medium Priority
Last Modified: 2013-11-20
Is there a way to append text to the end of a CEdit/View or CRichEditCtrl/View without using SetSel or SetWindowText? Neither are desirable in my situation.

I'm currently using SetSel, but I am not happy with it. I want to be able to easily select and copy text as some more text continues to be appended quite frequently, and without stoping the appending. That means SetSel() is not good because it changes the selection, making it really difficult to successfully select text, and copy it.

On another side, a lot of text will is appended, and the software can remain on for a long time. I do am planning to implement a dump to file feature later on, but in any case I think the GetWindowTest() and SetWindowText() is not practical due to the frequency of the appending, and the size of the data being transfered each time (even if only a few bytes are appended).

In this question's accepted anwser, is a mention to other ways of appending text to an edit box. Anyone would care to get me on the right track?

Sorry, about my lame english, I'm not native. I'm also new to EE, so if this question is worth more points, just tell.

Thanks a lot.
Question by:Djof
  • 2
LVL 23

Accepted Solution

Roshan Davis earned 600 total points
ID: 8110404
If you are using CRichEditCtrl or CRichEditView you can take the advantage of StreamIn function avalibale in the rich edit ctrl. The following links contains good examples of inserting text in a rich edit control.


good Luck
LVL 31

Expert Comment

ID: 8110932
hm ... at least for CEdit(View) I think there's no chance to
add text without SetWindowText() or ReplaceSel().

>That means SetSel() is not good because it changes the
>selection, making it really difficult to successfully select
>text, and copy it.
Well, you could simply store the current selection-range, call
SetSel/ReplaceSel and reset the previous selection afterwards

Maybe you could use a list box instead of a edit control but
with list box you can't select,cut&paste text.

Probably it's possible to implement your own control (derived
from CEdit) which is some kind of 'virtual' edit control (so
you store the complete text in a string but the edit control
only shows the visible part via SetWindowText ... you'd have
to handle scrolling and selection of more than the visible
text ... maybe difficult).


Author Comment

ID: 8112598

The problem with StreamIn is that it, as MSDN tells, "Replaces text in this CRichEditCtrl object with text from the specified input stream."

I need to append it. :(
Would anyone know if it's possible to change the StreamIn behavior?


I already use a RichEdit, but I included the CEdit in the question because I could have changed if the CEdit had any features that would have been usefull to me in this case.

Thanks for fast reply to both of you.

Author Comment

ID: 10295796
Mmm. This has been running long without anything new.

Daniel Lohmann's CEditLog found at codeproject (http://www.codeproject.com/editctrl/editlog.asp, I hope the link is good as codeproject seems to be down right now) comes closest to being the best solution possible. I still uses the select and replace method, but it handles case when the user is currently trying to select text in either directition, and makes sure the screen doesn't move by remembering the first visible line. The only problem with using this solution with a RichEditCtrl is that I have been unable to stop the painting, thus the flashing.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question