CListBox替换CComboBox就行
int CF200RFPowerMeterDlg::FindInstrument()
{
CEdit* pEdit = (CEdit*)(((CComboBox*)GetDlgItem(IDC_COMBO_INSTRUMENT))->GetWindow(GW_CHILD));
pEdit->SetReadOnly(TRUE);// 将输入框色设置为只读,但可以选择
vector<string> ConnectStringList = find();
((CComboBox*)GetDlgItem(IDC_COMBO_INSTRUMENT))->ResetContent(); //清空
if (ConnectStringList.size() == 1) {
((CComboBox*)GetDlgItem(IDC_COMBO_INSTRUMENT))->AddString(CString(ConnectStringList.front().c_str()));//加条目
((CComboBox*)GetDlgItem(IDC_COMBO_INSTRUMENT))->SetCurSel(0); //默认选第一个
((CComboBox*)GetDlgItem(IDC_COMBO_INSTRUMENT))->EnableWindow(FALSE);//禁止选择与编辑
displayDeviceState(BLACK, "Please insert device!");
}//Auto select
else if (ConnectStringList.size() > 1) {
for (int i = 0; i < ConnectStringList.size(); i++)
{
((CComboBox*)GetDlgItem(IDC_COMBO_INSTRUMENT))->AddString(CString(ConnectStringList.at(i).c_str()));
}
((CComboBox*)GetDlgItem(IDC_COMBO_INSTRUMENT))->SetCurSel(0);
((CComboBox*)GetDlgItem(IDC_COMBO_INSTRUMENT))->EnableWindow(TRUE);
displayDeviceState(BLACK, "There are " + CString(to_string(ConnectStringList.size()).c_str()) + " instruments,please select one");
}
else if (ConnectStringList.size() < 1) { displayDeviceState(BLACK, "Can not find instrument."); }
// TODO: 在此处添加实现代码.
return 0;
}
点击下箭头可调整下拉列表的大小。