MFC 下拉框Combo Box

下拉框常用的事件是Change事件。属性常用:Data(英文;分隔),Sort(是否排序)

    // OnInitDialog()中
    m_cbx.SetCurSel(0);//设置默认选项
    //OnBnClickedButton1()中
    m_cbx.AddString(TEXT("橙汁"));//添加在首位,与插入的区别是:插入更灵活
    // OnBnClickedButton2()中
    m_cbx.InsertString(1, TEXT("咖啡"));//插入,位置2处
    // OnBnClickedButton3()中
    m_cbx.DeleteString(2);//删除,位置3处
    // OnBnClickedButton4()中
    CString str;
    m_cbx.GetLBText(1,str);//获取标签内容
    MessageBox(str);
    // OnCbnSelchangeCombo1()事件函数中
    int index=m_cbx.GetCurSel();//当前索引
    CString str;
    m_cbx.GetLBText(index, str);//获取标签内容
    MessageBox(str);

【参考】https://www.bilibili.com/video/av52921336?p=15

原文地址:https://www.cnblogs.com/xixixing/p/11904474.html