怎样获取combo box内的一个值。且把它赋给一个字符串变量。问题一解决马上结帖。先谢谢

解决方案 »

  1.   

    用下面的函数int GetLBText( int nIndex, LPTSTR lpszText );void GetLBText( int nIndex, CString& rString );
      

  2.   

    int nIndex = m_ComboCtrl.GetCurSel();
    m_ComboCtrl.GetLBText(nIndex,m_Str);//m_Str中存放结果
      

  3.   

    更简单的办法:
    CString str;
    m_ComboCtrl.GetWindowText(Str);
    或者:
    char str[nMaxCount];//具体长度自己定
    m_ComboCtrl.GetWindowText(Str,nMaxCount);
      

  4.   

    up是呀是呀,这MSDN上的例子也很清楚:Example// The pointer to my combo box.
    extern CComboBox* pmyComboBox;// Dump all of the items in the combo box.
    #ifdef _DEBUG
       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;
       }
    #endif你看看这不所有的都有了:)
      

  5.   

    你可以到msdn的msdnie,里面的MainFrm 有详细的介绍如何处理的,up
      

  6.   

    补充一下:如果没有声明控件变量的话,用GetDlgItem();e.g: ((CComboBox*)(GetDlgItem(IDC_COMBO1)))->
          GetLBText(((CComboBox*)(GetDlgItem(IDC_COMBO1)))->GetCurSel(), str);