cmbobox FindString空

cmbobox FindString空,string,visual-c++,combobox,mfc,is-empty,String,Visual C++,Combobox,Mfc,Is Empty,MFC cmbobox允许用户对空字符串执行AddString。我只是通过在AddString之前和之后执行一个GetCount()来证明这一点;计数为0,然后变为1;GUI似乎也反映了这一点,因为它的列表是一个巨大的空框,当添加它时,它变成了一行 我还做了进一步的证明 int a = m_combo.GetCount(); CString sx= _T("Not empty string"); if(a == 1)

MFC cmbobox允许用户对空字符串执行
AddString
。我只是通过在
AddString
之前和之后执行一个GetCount()来证明这一点;计数为0,然后变为1;GUI似乎也反映了这一点,因为它的列表是一个巨大的空框,当添加它时,它变成了一行

我还做了进一步的证明

            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);
它返回
CB_ERR

这是空字符串条目的标准行为吗?官方文件没有说任何关于它的事情


如果是,最简单的覆盖方法是什么?资源中是否存在一些参数或变化来改变行为?如果没有,我正在考虑为字符串为空的情况派生或组合一个类

我为空字符串手动执行了此操作,它可以正常工作

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);
CString-sItem;
int idx_aux=CB_ERR;
//需要它,因为当我们向FindString、FindStringExact和SelectSring提供空字符串时,它们会返回CB_ERR!
if(m_name.IsEmpty())
{

for(int i=0;iA组合框是用户可见的控件。抛出空(不可见)控件的用例是什么字符串指向用户?对不实用的编程问题进行先发制人的否决投票。查看
FindStringExact
是否满足您的要求。
FindString
搜索以给定字符串开头的项目-当给定字符串为空时,这实际上没有意义。@IgorTandetnik:我使用
FindStringExact
进行了测试它也有同样的行为;它还返回
CB_ERR
。无论如何,请更新您的注释,因为您比我更关注文档。它的工作方式与您描述的方式相同:
FindString
匹配以作为函数调用字符串参数输入的前缀开头的条目;
FindStringExact
匹配与输入参数相等的条目。@IgorTandetnik:我打赌全世界的许多代码一定是错误地使用了
FindString
,在它真正应该使用
FindStringExact
的地方!这些函数有一个命名问题,因为人们会认为
FindString
是不区分大小写的e完全匹配,并且
FindStringExact
是区分大小写的完全匹配!使用
SetItemData
GetItemData
解决这个问题怎么样?而不是依赖于查找匹配空字符串。
 int idx= m_combo.FindString(-1, m_name);
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);