How would I append more text to an edit box win32 control?

Started by
4 comments, last by GeekPlusPlus 19 years, 11 months ago
Hello, I''ve got an edit box, and it''s got a few lines of text in it already. But I just want to add more text to the end of it. Is there a way to just append new text to it easily? or do I have to get the text that''s in it, add the new strings together and then put it back in the box? If I have to do it he second way could someone possibly give an example of how they might do it with STL? cause this is really the only string stuff I have and don''t want to go including that just to add 2 strings once... Thanks. - Newb Programmer: Geek++
- Newb Programmer: Geek++
Advertisement
send a message to the edit control like this:

SendMessage(hEditWnd, EM_SETSEL, 0, MAKELONG(0xffff, 0xffff) );

that should place the caret at the end of any text currently in the box.

then:
char c[1024];

SendMessage(hEditWnd, EM_REPLACESEL,NULL,(LPARAM)c);

I believe this will work, try it out. If not then I'll try to dig up some old code where I handled this issue.

EDIT: Also, I think you should also make sure that whatever character array you are using is null-terminated too.

[edited by - nervo on June 1, 2004 8:30:59 PM]
Well, R2D22U2..
alrighty, I have this:

SetDlgItemText(hWnd, CONTROL_EDIT, "line1\r\nline2");
SendMessage(hEdit, EM_SETSEL, 0, MAKELONG(0xffff, 0xffff));
SendMessage(hEdit, EM_REPLACESEL, 0x00, (LPARAM)"\r\nline3");

so I should get.
---------------
Line1
Line2
Line3
---------------

But I end up with

---------------

Line3
---------------

So it seems it''s still just replacing all the text.


- Newb Programmer: Geek++
- Newb Programmer: Geek++
quote:Original post by GeekPlusPlus
alrighty, I have this:

SetDlgItemText(hWnd, CONTROL_EDIT, "line1\r\nline2");
SendMessage(hEdit, EM_SETSEL, 0, MAKELONG(0xffff, 0xffff));
SendMessage(hEdit, EM_REPLACESEL, 0x00, (LPARAM)"\r\nline3");

so I should get.
---------------
Line1
Line2
Line3
---------------

But I end up with

---------------

Line3
---------------

So it seems it's still just replacing all the text.


- Newb Programmer: Geek++


OK, I just looked at my code..try this:

SendMessage(hEdit, EM_SETSEL,0xffff, 0xffff);

EDIT: My code went like this: (replace as necessary):
totalbufsize += GetWindowTextLength(hwnd_edit);	SendMessage(hwnd_edit,EM_SETSEL,(WPARAM)totalbufsize,(LPARAM)totalbufsize);	SendMessage(hwnd_edit,EM_REPLACESEL,0,(LPARAM)(clientoutput.c_str()));


[edited by - nervo on June 1, 2004 8:44:12 PM]
Well, R2D22U2..
if I use

SendMessage(hConsole, EM_SETSEL, 20, 20);

it works, because it selects form 20 to 20
, but if the text is ever past 20 it wouldn''t.

Seems kinda hacky just to put a huge number in there and assume it''ll never go past that =/



- Newb Programmer: Geek++
- Newb Programmer: Geek++
Yeah that works.

0xffff is just a neater looking way of doing a huge number.

Works for me. Thanks =)

Edit:

Woops shoudla read the rest. gettext length, that's much, much nicer.

Thanks a lot =)

- Newb Programmer: Geek++

[edited by - GeekPlusPlus on June 1, 2004 8:46:26 PM]
- Newb Programmer: Geek++

This topic is closed to new replies.

Advertisement