Solved

CEdit

Posted on 2002-03-13
11
626 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
while loop over for loop 7 119
withoutTen challenge 14 141
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 659
Increment column based of a FK 8 68
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.

751 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