CListBox::GetText

更新 : 2007 年 11 月

リスト ボックスから文字列を取得します。

int GetText(
   int nIndex,
   LPTSTR lpszBuffer 
) const;
void GetText(
   int nIndex,
   CString& rString 
) const;

パラメータ

  • nIndex
    取得する文字列の 0 から始まるインデックスを指定します。

  • lpszBuffer
    文字列を受け取るバッファへのポインタ。NULL 文字で終わる文字列を格納できるサイズのバッファを指定してください。文字列のサイズは GetTextLen メンバ関数を使って調べることができます。

  • rString
    CString オブジェクトへの参照。

戻り値

文字列の終端を示す NULL 文字を除いた文字列の長さ (バイト数) を返します。nIndex で不正なインデックスを指定した場合は、LB_ERR を返します。

解説

このメンバ関数の 2 番目の構文は、CString オブジェクトに文字列テキストを格納します。

使用例

// Dump all of the items in the list box.
CString str, str2;
int n;
for (int i = 0; i < m_myListBox.GetCount(); i++)
{
   n = m_myListBox.GetTextLen(i);
   m_myListBox.GetText(i, str.GetBuffer(n));
   str.ReleaseBuffer();

   str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
   AFXDUMP(str2);
}

必要条件

ヘッダー : afxwin.h

参照

参照

CListBox クラス

階層図

CListBox::GetTextLen

LB_GETTEXT

その他の技術情報

CListBox のメンバ