双击CListBox中的选项,怎么获取选中项的信息
如上图,127.0.0.1是CListBox中的一个列表项,双击127.0.0.1这个选项的时候,会产生一个ON_LBN_DBLCLK消息,在此消息的处理函数中,怎么获取双击的这个列表项的信息。比如获取这个列表项的名字等!
[解决办法]
获取当前选择行:
// The pointer to my list box.
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);
}
获取某行text:
// The pointer to my list box.
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;
}
你得学会读msdn上面写的很清楚的。