遍历MFC CComboBox的项

4

我需要遍历 CComboBox 中的项(字符串),以检查哪个字符串最长。我该如何获取列表中的每个项?

1个回答

7

尝试使用GetLBTextLen()函数。

以下是来自MSDN的示例:链接

// Dump all of the items in the combo box.
   CString str, str2;
   int n;
   for (int i=0;i < pmyComboBox->GetCount();i++)
   {
      n = pmyComboBox->GetLBTextLen( i );
      pmyComboBox->GetLBText( i, str.GetBuffer(n) );
      str.ReleaseBuffer();

      str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
      afxDump << str2;
   }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接