MFC列表框的使用
1.初始化并给默认值
//初始化列表框,并给默认选择
((CListBox*)GetDlgItem(IDC_LIST1))->AddString("1");
((CListBox*)GetDlgItem(IDC_LIST1))->AddString("2");
((CListBox*)GetDlgItem(IDC_LIST1))->AddString("3");
((CListBox*)GetDlgItem(IDC_LIST1))->AddString("4");
((CListBox*)GetDlgItem(IDC_LIST1))->SetCurSel(2);
2.读取
//列表框
void CDialogDlg::OnButton5()
{
// TODO: Add your control notification handler code here
int index;
index=((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel();//获取光标所在位置
((CListBox*)GetDlgItem(IDC_LIST1))->GetText(index,m_list);
MessageBox(m_list);
}