Solved

CEdit

Posted on 2002-03-13
11
594 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
format the code in java 6 85
twoTwo  challenge 35 92
building a service to accessed via telnet client, want colors ? 4 80
x-bar in Google Sheets 2 24
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

929 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

12 Experts available now in Live!

Get 1:1 Help Now