简体   繁体   中英

MFC displaying multiple-lines of text in Edit Control box

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.

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM