1.新建一個基于對話框的Dialog
2.拖一個Combo Box控件到對話框中,如圖所示

加控件.png
3.定義一個自變量choose
4.將自變量與控件相關(guān)聯(lián),在DoDataExchange()實現(xiàn)
DDX_Control(pDX, IDC_COMBO1, m_comb1);
DDX_Control(pDX, IDC_COMBO2, m_comb2);
5.設(shè)置控件內(nèi)的數(shù)據(jù)
(1)所需的數(shù)據(jù)均為數(shù)字,可以以循環(huán)實現(xiàn)
for (int i = 0; i<2; i++)
{
choose.Format(_T("%d"), i + 1);
m_comb1.InsertString(i, choose);
}
m_comb1.SetCurSel(0);//預置
(2)所需的內(nèi)容為固定內(nèi)容,可以以數(shù)組形式實現(xiàn)
CString str2[] = { _T("自定義"),_T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"),_T("7")};
for (int i = 0; i<8; i++)
{
int judge_tf = m_comb2.InsertString(i, str1[i]);
if ((judge_tf == CB_ERR) || (judge_tf == CB_ERRSPACE))
MessageBox(_T("build baud error!"));
}
m_comb2.SetCurSel(0);//預置
6.編譯運行后即可實現(xiàn)其功能