FindStringExact

 
 
 

Code::

CComboBox::FindStringExact
int FindStringExact( int nIndexStart, LPCTSTR lpszFind ) const;
当nStartAfter=-1时,则表示查的整个列表框的的项目

 

判断是否存在时用条件

  列表中有   字符串 str 返回值>= 0     
  列表中没有 字符串 str 返回值= -1       
 

   

项目存在 不执行

    if (返回值>0 ) 项目存在;return;

    if (返回值!=-1 ) 项目存在;return;

 

项目不存在 执行   

if (返回值==-1 )

    {

        项目不存在;

    }

 
 
 

Code::判断列表框中的项目是否已经存在了

void CWwwDlg::OnButton1()
{
    CString s;
    GetDlgItemText(IDC_COMBO1,s);
    int i = ((CComboBox*)GetDlgItem(IDC_COMBO1))->FindString(-1,s);
    CString s2;
    s2.Format("%d",i);
    MessageBox(s2);
}

效果图:

这个问题需要解决

a != aaaa

完全相等才相等!

如何处理

 

Code:: FindStringExact可以解决FindString出现的问题

void CWwwDlg::OnButton1() 
{
    CString s;
    GetDlgItemText(IDC_COMBO1,s);
    if (s.IsEmpty()) return;
    int i = ((CComboBox*)GetDlgItem(IDC_COMBO1))->FindStringExact(-1,s);
    CString s2;
    s2.Format("%d",i);
    
    if (i>=0)
    {
        MessageBox("项目已存在!");
        return;
    }
    else
    {
        MessageBox("此项目不存在");
    }
    
} 
  

效果图:

 




原文地址:https://www.cnblogs.com/xe2011/p/3576988.html