向combobox控件中添加元素

函数定义:
bool FillComboBox(CComboBox* pc, CStringList& slValues, bool bOnlyUniqueValues = false);
函数实现:
bool FillComboBox(CComboBox* pc, CStringList& slValues, bool bOnlyUniqueValues)
{
	POSITION pos;
	CString  s;

	pc->ResetContent();
	for (pos = slValues.GetHeadPosition(); pos != NULL;) {
		s = slValues.GetNext(pos);
		if (bOnlyUniqueValues) {
			// String already in combobox
			if (pc->FindStringExact(0, s) != CB_ERR) {
				continue;
			}
		}
		pc->AddString(s);
	}

	return true;
}

将字符串列表中的字符串加入combobox控件中,如:

FillComboBox(&m_combobox, strList);

其中m_combobox为combobox控件相关联的变量,strList为CStringList类型,里面保存的是要加入combobox控件中的字符串。

原文地址:https://www.cnblogs.com/pengjun-shanghai/p/5133662.html