CListBox::GetSelItems 是 MFC(Microsoft Foundation Classes)中的 CListBox 类的公共方法之一,用于获取当前被选择项的索引。

以下是该方法的简要说明:
int CListBox::GetSelItems(
   int nMaxItems,       // 指定数组的最大大小
   LPINT rgIndex        // 用于存储选定项索引的整数数组
) const;

参数说明:
  •  nMaxItems:指定数组 rgIndex 的最大大小,即数组能够容纳的最大选定项数目。

  •  rgIndex:用于存储选定项索引的整数数组。


返回值:
返回实际选定项的数量。如果返回值为 LB_ERR,则表示出现错误。

示例用法:
CListBox listBox; // 假设有一个 CListBox 对象

int nMaxItems = listBox.GetCount(); // 获取列表框中项的总数
int* rgIndex = new int[nMaxItems]; // 为存储索引的数组分配内存

int nSelectedItems = listBox.GetSelItems(nMaxItems, rgIndex);

// 现在,rgIndex 数组中包含了被选择项的索引,数量为 nSelectedItems

// 释放分配的内存
delete[] rgIndex;

此方法允许你获取 CListBox 控件中当前被选择的项的索引。


转载请注明出处:http://www.pingtaimeng.com/article/detail/18481/MFC/CListBox