Solved

CEdit

Posted on 2002-03-13
11
586 Views
Last Modified: 2013-11-20
Hi!
i have a CEdit object in my CDialog.
This CEdit object is a MULTILINE style.

now i want to add a string to this CEdit.

i don't want to use SetWindowText function because this function erase the previous text that my CEdit contain.

   
How can i add a string into CEdit without erasing the previous one.

any help will be appriciate.
    Guy Eliyahu.
0
Comment
Question by:GEliyahu
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 6860011
Hi,

Just a try...

How about sending WM_CHAR messages???? Like

char chTemp[10];
strcpy(hTemp, "Hello");

int nChar = 0;
for(int nIndex = 0; nIndex < strlen(chTemp); nIndex++)
{
    nChar = chTemp[nIndex];
    m_MyEditCtrl.SendMessage(WM_CHAR, nChar);
}

Try it out.....
VinExpert
0
 

Author Comment

by:GEliyahu
ID: 6860179
Your code is not functioning as well..
and besides...don't you think that a function like AddWindowText() that similat to SetWindowText, is exist?
 
one solution that i came up with is..

m_Edit.GetWindowText(String);
String+="Hello";
m_Edit.SetWindowText(String);

But if i will have a string with a million charachters...
why do i have to deal with SetWindowText function instead of just adding a text...
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 6860301
Hi,

U want to add the new text line by line? In that case CListBox is a best option, where in can add a new text entry in new line using AddString(...) function of CListBox without altering or handling the old data. There is no straight way to do that in CEdit control.

VinExpert
0
 

Author Comment

by:GEliyahu
ID: 6860320
I cant use lisr ctrl because it's not a line by line exactly.
some times i had to enter a real long sentece to the CEdit and a list ctrl is not a good place to store a line like this.

Remark: This CEdit is actually a similar to a log file.

i enter there a notification to a user.

GEliyahu.
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 6860332
Hi,

I suggested the List box not the list control..... Usually I preffer a list box for the information box as I can go on adding the new status strings as and when the events occure.

VinExpert
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:Crius
ID: 6863023
There is no AddWindowText(), but your solution of GetWindowText() and SetWindowText() is the standard way.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6870530
You must use the SetSel and ReplaceSel like so:

m_ctlEdit.SetSel(-1,-1); // cursor to end of last line
m_ctlEdit.ReplaceSel( "this text is added!\n" );

-- Dan
0
 

Author Comment

by:GEliyahu
ID: 6873615
Nice solution!
But the only problem is that the text "this text is added in!" is added before the exist text in the CEdit control.
my purpose is to insert the text after the existing text .

GEliyahu.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 30 total points
ID: 6873724
Don't forget to put this line:

m_ctlEdit.SetSel(-1,-1);

It sets the cursor to the end of the text.  Then the new text will be added to the end of the existing text.

-- Dan
0
 

Author Comment

by:GEliyahu
ID: 6873771
Thanks dan.
i did a mistake with your code but i have overcome it finnaly.
GEliyahu.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6875537
I knew that.

-- Dan
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now