Solved

CEdit

Posted on 2002-03-13
11
614 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
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.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 51
no14 challenge 14 70
Change to event 1 118
how to use laptop or pad camera in vb.net windows application 2 86
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

861 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