views:

336

answers:

1

In my C++ Win32 GUI application I have a dialog with an edit control created from a dialog template:

EDITTEXT   IDC_EDIT_Id, X, Y, W, H,
    ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL

Whenever I manually input multiline text with carriage returns and call GetWindowText() the retrieved text is broken into lines with CR and LF characters as expected. However when I try to put the same text back into the edit control with SetWindowText() the control displays that text as a single string.

Why does it exhibit such behaviour and how do I workaround this?

+3  A: 

When you put the text back with SetWindowText, please make sure you are using \r\n for your newlines.

Works fine for me.

This will display the text on 2 lines:

GetDlgItem(IDC_EDIT1)->SetWindowText(_T("Hello\r\nWorld!"));

Hello
World!

This will display the text on 1 line:

GetDlgItem(IDC_EDIT1)->SetWindowText(_T("Hello\nWorld!"));

HelloWorld!

Brian R. Bondy
Yes, that was it. Now I normalize as following: first replace all "\n" with "", then all "\r" with "\r\n". Thanks a lot.
sharptooth