Edit Boxes

Started by
4 comments, last by LordN 20 years, 8 months ago
I have a program which contains two edit boxes. The first edit box is a single line and the other is a multiline. When the user presses enter, the text entered in the single box is saved to a string. However, I can not figure out how to make it so that when enter is pressed, the text entered in the single line box appears in the multiline box, and then the next time enter is pressed the new text is entered into the second box a line down from the original text.
Advertisement
Operating system? Library? Language?
I am using Visual C++ 6.0, running Windows XP
Plain win32 calls or MFC?

I know little of MFC, but I can make some guesses with win32 code. I'm guessing that, if you append a newline character followed by the string you want to add, it'll appear as a new line.
One way to do this is to read the entire text of the textbox (with WM_GETTEXTLENGTH followed by WM_GETTEXT), append the newline character and your string, then use WM_SETTEXT to write it back to the textbox.
Another might be to get the length of the textbox (WM_GETTEXTLENGTH), set the selection range to the end of the textbox (EM_SETSEL), then use EM_REPLACESEL to append a newline and your string.

Hopefully these'll work out.

EDIT: I've tested them; it seems that two characters ("\r\n") are necessary to indicate a line break.

[edited by - Beer Hunter on July 26, 2003 6:09:59 AM]
you can also just use GetWindowText and SetWindowText (aliases for WM_GETTEXT/SETTEXT)
Your suggestion worked, thanks for the help.

This topic is closed to new replies.

Advertisement