次の方法で共有


CComboBox::GetLBText

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

int GetLBText(
   int nIndex,
   LPTSTR lpszText 
) const;
void GetLBText(
   int nIndex,
   CString& rString 
) const;

パラメーター

  • nIndex
    コピーするリスト ボックス内の文字列のインデックスが含まれています。

  • lpszText
    文字列を受け取ることになっているバッファーへのポインター。バッファーは文字列と終端の null 文字の十分な領域を持つ必要があります。

  • rString
    CString への参照。

戻り値

終端の NULL 文字を除いた文字列の長さ (バイト単位)。nIndex が有効なインデックスを指定しない場合、戻り値は CB_ERRです。

解説

このメンバー関数の 2 番目のフォームは、項目のテキストを含む CString のオブジェクトを塗りつぶします。

使用例

// Dump all of the items in the combo box.
CString str1, str2;
int n;
for (int i = 0; i < m_pComboBox->GetCount(); i++)
{
   n = m_pComboBox->GetLBTextLen(i);
   m_pComboBox->GetLBText(i, str1.GetBuffer(n));
   str1.ReleaseBuffer();

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

必要条件

ヘッダー: afxwin.h

参照

関連項目

CComboBox クラス

階層図

CComboBox::GetLBTextLen

CB_GETLBTEXT