VC怎样获得列表控件的当前选项(即Item的值)?

2024-11-02 07:02:44
推荐回答(3个)
回答1:

CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_YOURLISTCONTROL);
ASSERT(pListCtrl != NULL);
POSITION pos = pList->GetFirstSelectedItemPosition();
if (pos == NULL)
   TRACE0("No items were selected!\n");
else
{
   while (pos)
   皮茄{
      int nItem = pList->GetNextSelectedItem(pos);
  巧搜    TRACE1("Item %d was selected!\n", nItem);
     燃宽察 // you could do your own processing on nItem here
   }
}

回答2:

GetDlgItem(IDC_XX) 获虚大取控件指针差斗竖或销察句柄
int i=CListBox::GetCurSel();
CListBox::GetText(i)
CListCtrl::GetItemText(i);

回答3:

GetDlgItem(IDC_XX),基类不同可能参数不同,返回HWND