小弟现在在公司里没有书看没有资料查只能请教各位了:拖了一个LISTBOX,ID为IDC_LST_ITEMS,指定变量名叫做m_sItems,对其基本使用我一点都不了解,希望能给出一些示例代码谢谢!比如怎么添加, 在指定条目后添加,怎么删除一条,
当前条目怎么访问,
指定的变量m_sItems怎么使用等等。

解决方案 »

  1.   

    返回选定的串
    CListBox::GetTextThis method retrieves a string from a list box. The second form of this method fills a CString object with the string text.
    int GetText( 
                 int nIndex, 
                 LPTSTR lpszBuffer ) 
    const; void GetText( 
                 int nIndex, 
                 CString& rString ) 
    const; ParametersnIndex 
    Specifies the zero-based index of the string to be retrieved. lpszBuffer 
    Points to the buffer that receives the string. The buffer must have sufficient space for the string and a terminating null character. The size of the string can be determined ahead of time by calling the GetTextLen method. rString 
    Specifies a reference to a CString object. Return Value
    Returns the length, in bytes, of the string, excluding the terminating null character. If nIndex does not specify a valid index, the return value is LB_ERR.Example
    // Pointer to the myListBox.
    extern CListBox* pmyListBox;// Dump all of the items in the list box.
    #ifdef _DEBUG
      CString str, str2;
      int n;
      for (int i=0;i < pmyListBox->GetCount();i++)
      {
        n = pmyListBox->GetTextLen( i );
        pmyListBox->GetText( i, str.GetBuffer(n) );
        str.ReleaseBuffer();    str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
        afxDump << str2;
      }
    #endif返回当前选定的串的索引号
    CListBox::GetCurSelThis method retrieves the zero-based index of the currently selected item, if any, in a single-selection list box. GetCurSel should not be called for a multiple-selection list box.int GetCurSel( ) 
    const; Return Value
    The zero-based index of the currently selected item. It is LB_ERR if no item is currently selected or if the list box is a multiple-selection list box.
    Example
    // Pointer to the myListBox.
    extern CListBox* pmyListBox;// Select the next item of the currently selected one.
    int nIndex = pmyListBox->GetCurSel();
    int nCount = pmyListBox->GetCount();
    if ((nIndex != LB_ERR) && (nCount > 1))
    {
      if (++nIndex < nCount)
      pmyListBox->SetCurSel(nIndex);
      else
        pmyListBox->SetCurSel(0);
    }