MFC在编辑控件框中显示多行文本

发布于 2024-12-27 22:01:33 字数 212 浏览 4 评论 0原文

我正在尝试实现一个显示文件名的工具。 我想通过使用 SetWindowText() 方法来做到这一点。 但是,当我尝试在循环中使用此方法时, 文本一行显示,并且不断刷新。

这是代码片段

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

请帮助。!谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里梦着梦中梦 2025-01-03 22:01:33

SetWindowText 用您提供的字符串替换当前窗口文本。
因此,如果你想用它显示多行,你首先必须创建一个多行字符串。

一个简单的例子:

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

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);
三月梨花 2025-01-03 22:01:33

另一种经过时间考验的同时显示多个名称的方法是列表框。 MFC 提供了一个带有 CListBox 类的漂亮包装器(请参阅 http://msdn.microsoft.com/en-us/library/y04ez4c9%28v=vs.80%29.aspx)。如果列表很长,这还有一个额外的好处,那就是可滚动和(可选)可排序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文