Dear all,
I have a little problem with an edit control.
I'd like to add text and add lines. "Add" means appending text to the text already in there.
Adding text: This can be done using EM_Replacesel, and making sure the selection corresponds to nothing but the end of the text that's already in there.
It works in principle by this function:
int Edit_AddText(HWND hEdit, char* txt)
{
//deselect everything furst
SendMessage(hEdit,
(UINT) EM_SETSEL,
(WPARAM) -1,
(LPARAM) 0);
SendMessage(hEdit,
(UINT) EM_REPLACESEL,
(WPARAM) FALSE,
(LPARAM) txt);
}
So if I want to add a line, rather than just text, I thought this should work:
int Edit_AddLine(HWND hEdit, char* txt)
{
char* Newline = "\n"; // or "\n\r" or "\r" etc
Edit_AddText(hEdit, txt);
Edit_AddText(hEdit, Newline);
}
But it does NOT work correctly. The "\n" (or any combi of "\n" and/or "\r" gives a weirdo character in the edit. That's annoying. I also tried forcing ascii(13) and/or ascii(10) into the strings with code, but the result is the same :cry: . The Edit simply seems resistant to such characters.
How do I get around it?
Many thanks for your help.
Yates
What simply adding an empty string like ""?
"\r\n" works.
I tried this
SetWindowText(ehwnd, "Qwerty");
int lResult = GetWindowTextLength(ehwnd);
SendMessage(ehwnd, (UINT) EM_SETSEL, (WPARAM)lResult, (LPARAM) -1);
SendMessage(ehwnd,(UINT) EM_REPLACESEL,(WPARAM) FALSE,(LPARAM) "\r\nFred");
John
Oooooh,
JohnF you are in fact right, "\r\n" seem to be the key to success (hey, I thought it was either deodorant or a fancy iPod).
Considering that I wrote that I had tried any combi of \n and \r it is rather dumb that I had not tried \r\n :oops:
Many thanks and have a nice weekend
Y.
You know:
CR (carriage return) = 0x13 = \r
LF (line feed) = 0x10 = \n
and the line ending protocols for three main systems:
MSDOS/WINDOWS: CR+LF
UNIX: LF
MAC: CR
Haven't you ever downloaded a source file from Internet and, when opened into notepad, it seemed as if the writer of the file had his/her enter key broken? The reason is that the original programmer surelly had his/her programming session in a UNIX system, and end of lines are encoded with only LF, that doesn't conform to Windows criteria of CR+LF.
Controls (and any other thing) in Windows will look for CR+LF (there is some exception although, where only LF is enough)