遍历MFC CComboBox的项目

jon*_*nsb 2 mfc visual-c++

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

Ada*_*rce 5

尝试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;
   }
Run Code Online (Sandbox Code Playgroud)

  • 我杀了你...和MSDN ...一个很好的答案,但是对迈克的热爱,一个函数调用进行了测试。int count = pmyComboBox-&gt; GetCount(); (2认同)