1.新建一個基于對話框的Dialog
2.拖一個Combo Box控件到對話框中,如圖所示
加控件.png
3.定義一個自變量choose
4.將自變量與控件相關聯,在DoDataExchange()實現
DDX_Control(pDX, IDC_COMBO1, m_comb1);
DDX_Control(pDX, IDC_COMBO2, m_comb2);
5.設置控件內的數據
(1)所需的數據均為數字,可以以循環實現
for (int i = 0; i<2; i++)
{
choose.Format(_T("%d"), i + 1);
m_comb1.InsertString(i, choose);
}
m_comb1.SetCurSel(0);//預置
(2)所需的內容為固定內容,可以以數組形式實現
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.編譯運行后即可實現其功能