VC:CListBox(添加项、设置图片、获取总项数、获取选中的项、获取项文本)
1、初始化:对话框属性中Selection项,选择Multiple
m_listbox.AddString("Colomn1");
m_listbox.AddString("Colomn2");
m_listbox.AddString("Colomn3");
m_listbox.AddString("Colomn4");
m_listbox.InsertString(1,"Insert 1");
m_listbox.InsertString(2,"Insert 2");
// m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//HICON hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
// m_listbox.SetIcon(m_hIcon,true);
2、获取列表框信息
CString message="您的爱好有:";
CString str;
int num=m_listbox.GetSelCount();
int m[10];
for(int i=0;i<10;i++)
{
m[i]=-1;
}
m_listbox.GetSelItems(num,m);
for(int j=0;j<10;j++)
{
if(m[j]!=-1)
{
m_listbox.GetText(m[j],str);
message+=str;
}
}
AfxMessageBox(message);