MFC CComboBox允许个人执行空字符串的AddString。我刚刚证明了,通过在GetCount()之前执行一个AddString(),在AddString之后执行另一个;计数为0,那么它就变成了1;图形用户界面似乎也反映了它,因为它的列表是一个巨大的空框,当添加它成为一行时。
我还进一步证明了这一点
int a = m_combo.GetCount();
CString sx= _T("Not empty string");
if(a == 1)
m_combo.GetLBText(0, sx);
TRACE(_T("Start<%s>End"), sx);输出窗口显示
File.cpp(9) : atlTraceGeneral - Start<>End因此,我们得出sx变量是空的。
然后,我做了一个FindString,它有一个CString m_name变量,它是空的:
int idx= m_combo.FindString(-1, m_name);它还返回CB_ERR!
这是空字符串条目的标准行为吗?官方文件什么也没说!
如果是的话,最简单的方法是什么?资源中是否有一些参数或变化来改变行为?如果没有,我正在考虑派生或组合一个类,只用于字符串为空的情况!
发布于 2016-07-12 17:12:38
我手动为空字符串做了它的工作!
CString sItem;
int idx_aux= CB_ERR;
// need it because FindString, FindStringExact and SelectSring return CB_ERR when we provide an empty string to them!
if(m_name.IsEmpty())
{
for (int i=0; i<m_combo.GetCount(); i++)
{
m_combo.GetLBText(i, sItem);
if(sItem.IsEmpty())
{
idx_aux= i;
break;
}
}
}
else
idx_aux= m_combo.FindString(-1, m_name);https://stackoverflow.com/questions/38272629
复制相似问题