动态创建Combobox

来源:互联网 发布:室内设计bim软件 编辑:程序博客网 时间:2024/06/06 21:42
#define MAX_COUNT 3#define IDC_COMBOBOX 1112CComboBox m_combo[MAX_COUNT];afx_msg void OnSelchangeCombo(UINT nID);BEGIN_MESSAGE_MAP(CXXXDlg, CDialog)ON_CONTROL_RANGE(CBN_SELCHANGE, IDC_COMBOBOX, IDC_COMBOBOX+MAX_COUNT, OnSelchangeCombo)END_MESSAGE_MAP()// 初始化函数OnInitDialog函数中创建combobox控件for(int i=0; i<MAX_COUNT; i++){m_combo[i].Create(WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST, CRect(0, i*30, 100, 100 + i*30),this, IDC_COMBOBOX + i);m_combo[i].AddString(_T("AAAAAA"));m_combo[i].AddString(_T("BBBBBB"));                m_combo[i].AddString(_T("CCCCCC"));m_combo[i].SetCurSel(0);}// 响应CBN_SELCHANGEvoid CXXXDlg::OnSelchangeCombo(UINT nID) {// TODO: Add your control notification handler code hereint nIndex = nID - IDC_COMBOBOX;CString strText(_T(""));m_combo[nIndex].GetLBText(m_combo[nIndex].GetCurSel(), strText);AfxMessageBox(strText);}


原创粉丝点击