我用GetWindowsText()方法,发现有的值正确,有的值不正确。另外,我用的是AddString()方法,所以使用GetCursel()方法虽然能得到当前所选的索引号,但和字符串没有对应关系,用什么方法能得到我选中的字符串呢?请大家帮忙,另外,本人积分不多了,只能给三十分,请体谅。

解决方案 »

  1.   

    CComboBox::GetLBText
    This method retrieves a string from the list box of a combo box. The overloaded form of this method fills a CString object with the text of the item.int GetLBText( 
    int nIndex, 
    LPTSTR lpszText ) 
    const; void GetLBText( 
    int nIndex, 
    CString& rString ) 
    const; 
    Parameters
    nIndex 
    Contains the zero-based index of the list box string to copy. 
    lpszText 
    Pointer to a buffer that is to receive the string. The buffer must have sufficient space for the string and a terminating null character. 
    rString 
    A reference to a CString. 
    Return Value
    The length, in bytes, of the string, excluding the terminating null character. If nIndex does not specify a valid index, the return value is CB_ERR.Example
    // The pointer to a combo box.
    extern CComboBox* pmyComboBox;// Dump 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;
      }
    #endifRequirements
      Windows CE versions: 1.0 and later
      Header file: Declared in Afxwin.h
      Platform: H/PC Pro, Palm-size PC, Pocket PCSee Also
    CComboBox::GetLBTextLen 
      

  2.   

    str.GetBuffer(n) 之后要用str.ReleaseBuffer()才能获得值,为什么呢,我看了相关的文档后,也不知道为什么,只是这样做了!