Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CEdit

Posted on 2002-03-13
11
Medium Priority
?
649 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:Vinayak Kumbar
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:Vinayak Kumbar
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
Industry Leaders: 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:Vinayak Kumbar
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 120 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

772 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