我有一个 CComboBox类控件,定义一个CString类的接受他的内容。
如果CComboBox的内容是空,程序就会报错。虽然不至于退出,可是看这不爽。
我怎么让他在空的时候RETRUN;啊。
      CString strCBText;
      if(判断)
        return ;
      m_ComboSonger.GetLBText(m_ComboSonger.GetCurSel(),strCBText);

解决方案 »

  1.   

     您是想判断strCBText是否为空是吗?
      

  2.   

           if(strCBText.IsEmpty())
     {
           MessageBox("请您选择活动的房间号","错误",MB_ICONERROR);
       return;
     }
    我想这样做,但是他在 m_ComboSonger.GetLBText(m_ComboSonger.GetCurSel(),strCBText);
    就出错了 !!!!!!!
      

  3.   

    CString::IsEmpty     
      BOOL   IsEmpty(   )   const;   
        
      Return   Value   
        
      Nonzero   if   the   CString   object   has   0   length;   otherwise   0.   
        
      Res   
        
      Tests   a   CString   object   for   the   empty   condition. 
      

  4.   


    if(m_ComboSonger.GetCount()<1)
    {
        return ;
    }
      

  5.   

    判断m_ComboSonger当前EDIT筐中没有内容返回
      

  6.   

    if(m_ComboSonger.GetCount()<1)
    {
        return ;
    }
    这样不行,因为m_ComboSonger是有内容的,你这样我以后的代码都不能执行了。
      

  7.   

    有内容的话GetCount() 会小于1吗
      

  8.   

    int nsel=m_ComboSonger.GetCurSel();
    if (nsel!= CB_ERR)
       m_ComboSonger.GetLBText(nsel,strCBText);
      

  9.   

    CComboBox::GetCountint GetCount( ) const;返回值:
    返回项的个数。该值比最后一项的下标要大1(因为下标是从0开始计算的)。出错时返回CB_ERR。说明:
    本函数用于取得组合框中列表框中项的个数。如果只有一项,不会返回啊。请参阅:CB_GETCOUNT 
      

  10.   

    我觉得10楼说的是正确的,出错不是因为count为0,而是因为当前选中的是-1。int nIndex = m_ComboSonger.GetCurSel();
    int nCount = m_ComboSonger.GetCount();
    if ((nIndex == LB_ERR) || (nCount < 1))
        return;或者直接用GetWindowText