I need to iterate through the items (strings) in a CComboBox to check which string is the longest. How can I get each item in the list?
我需要遍历CComboBox中的项(字符串)以检查哪个字符串最长。如何获取列表中的每个项目?
1 个解决方案
#1
Try the GetLBTextLen() function
试试GetLBTextLen()函数
Here's an example from MSDN:
这是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;
}
#1
Try the GetLBTextLen() function
试试GetLBTextLen()函数
Here's an example from MSDN:
这是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;
}