MFC displaying multiple-lines of text in Edit Control box

18,474

Solution 1

SetWindowText replaces the current window text with the string you provide.
So, if you want to show multiple lines with it, you first have to create a multi-line string.

A quick example:

CStringArray names;

// Fill names

CString str;
for (INT_PTR i = 0; i < names.GetCount() ; ++i)
{
    str += names[i] + _T("\r\n");
}

c_MyEdit.SetWindowText(str);

Solution 2

Another time-tested method of showing multiple names at once is the list box. MFC provides a nice wrapper with the CListBox Class (see http://msdn.microsoft.com/en-us/library/y04ez4c9%28v=vs.80%29.aspx). This has the added benefit of being scrollable and (optionally) sortable if the list is long.

Share:
18,474
user1047092
Author by

user1047092

Updated on June 27, 2022

Comments

  • user1047092
    user1047092 almost 2 years

    I am trying to implement a tool that displays file names. I would like to do this by using SetWindowText() method. However, When I was trying to use this method in a loop, the text is displayed in one line and it is continuously refreshed.

    here is code snippet

    for (int i = 0; i<10; i++)
    {
      SetWindowText(filenames);
    }
    

    please help.! thanks.