visual-c++ - 遍历 MFC CComboBox 的项目

标签 visual-c++ mfc

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

最佳答案

尝试 GetLBTextLen() 函数

这是一个 example from 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;
   }

关于visual-c++ - 遍历 MFC CComboBox 的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/380784/

相关文章:

winapi - 为什么 LoadResource/LockResource 有时会返回串联的资源数据?

visual-c++ - 如何检测CListCtrl选择更改?

c++ - 如何区分ascii值和数字?

c++ - gcc 和 MSFT CL 之间的位域结构大小不同

c++ - uint8 显示奇怪的字符

c++ - ASSERT 在 CDC SelectObject() 调用上失败 - 我可以尝试什么?

c++ - OLEDragDrop 事件与已编译的 exe 一起使用,但在调试时不起作用

c++ - 模板继承的 VC++ 错误

c++ - 如何正确调用 thiscall 函数,这是一个 mfc 控件

c# - 面向 future 的大型 UI 应用程序 - 具有 2008 功能包的 MFC 或 C# 和 Winforms?