Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

GeekPlusPlus

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

This topic is 5226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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++

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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++

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!