日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

CListBox用法总结

發(fā)布時(shí)間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CListBox用法总结 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

CListBox用法總結(jié)
用法
屬性Style
Selection
Single — 單選
Multiple — 多選(LBS_MULTIPLESEL)
None — 不可選(LBS_NOSEL)
Sort
對(duì)應(yīng)Style: LBS_SORT

Insert Item
int AddString(LPCTSTR lpszItem);
int InsertString(int nIndex,
LPCTSTR lpszItem);

Delete Item
int DeleteString(UINT nIndex);
//清空
void ResetContent();

Selection
int GetCurSel( ) const;
int SetCurSel(int nSelect);
int GetSelCount( ) const;
int GetSelItems(int nMaxItems,
LPINT rgIndex) const;
代碼示例:獲取選中項(xiàng)并輸出
假設(shè)CListBox控件變量名為m_lbTest
// 1.Selection = Single-----------------------------------
int nSelIndex = m_lbTest.GetCurSel();
if (nSelIndex == LB_ERR) //no item is currently selected
{
AfxMessageBox(TEXT(“no item is currently selected”));
}
else
{
CString cstr;
m_lbTest.GetText(nSelIndex, cstr);
AfxMessageBox(cstr);
}

// 2.Selection = Multiple----------------------------------
int nSelCnt = m_lbTest.GetSelCount();
if (nSelCnt == LB_ERR) //the list box is a single-selection list box
{
AfxMessageBox(TEXT(“the list box is a single-selection list box”));
return;
}
if (nSelCnt == 0) //no item is currently selected
{
AfxMessageBox(TEXT(“no item is currently selected”));
return;
}
int* pnSelIndex = new int[nSelCnt];
m_lbTest.GetSelItems(nSelCnt, pnSelIndex);
for (int i=0; i<nSelCnt; ++i)
{
CString cstr;
m_lbTest.GetText(pnSelIndex[i], cstr);
AfxMessageBox(cstr);
}
delete[] pnSelIndex;

Other
// 獲取Text
void GetText(int nIndex,
CString& rString) const;
// Get/Set item associated data
DWORD_PTR GetItemData(int nIndex) const;
int SetItemData(int nIndex,
DWORD_PTR dwItemData);
注意:
1.GetItemData在沒(méi)有通過(guò)SetItemData設(shè)置每一項(xiàng)的關(guān)聯(lián)數(shù)據(jù)時(shí)返回NULL.
2.對(duì)應(yīng)的GetItemDataPtr,SetItemDataPtr其實(shí)和GetItemData,SetItemData本質(zhì)上是一模一樣的
我們可以看下源碼
int CListBox::SetItemDataPtr(int nIndex, void* pData)
{ return SetItemData(nIndex, (DWORD_PTR)(LPVOID)pData); }
看來(lái)增加這兩個(gè)函數(shù)只是使意義更明確些,有點(diǎn)不懂微軟了。

動(dòng)態(tài)創(chuàng)建CListBox控件
黑色非標(biāo)準(zhǔn)3D邊框:
CListBox *pMyListBox = new CListBox();
pMyListBox->Create(
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | LBS_NOTIFY | LBS_MULTIPLESEL,
CRect(10, 10, 100, 100),
this,
1234);
pMyListBox->SetFont(this->GetFont());

pMyListBox->AddString(TEXT(“123”));
pMyListBox->AddString(TEXT(“456”));
pMyListBox->AddString(TEXT(“789”));

標(biāo)準(zhǔn)3D邊框:
CListBox *pMyListBox = new CListBox();
pMyListBox->CreateEx(
WS_EX_CLIENTEDGE,
TEXT(“LISTBOX”),
TEXT(""),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | LBS_NOTIFY | LBS_MULTIPLESEL,
10, 10, 100, 100,
this->GetSafeHwnd(),
(HMENU)1234);
pMyListBox->SetFont(this->GetFont());

pMyListBox->AddString(TEXT(“123”));
pMyListBox->AddString(TEXT(“456”));
pMyListBox->AddString(TEXT(“789”));

總結(jié)

以上是生活随笔為你收集整理的CListBox用法总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。