仅为初学者提供。
1、在xml文件中,有如下关系:
<Shops>
<Shop NO="0" Name="山东省">
<Units>
<Unit NO="0">济南</Unit>
<Unit NO="1">青岛</Unit>
<Unit NO="2">潍坊</Unit>
<Unit NO="3">烟台</Unit>
</Units>
</Shop>
<Shop NO="1" Name="湖南省">
<Units>
<Unit NO="0">长沙</Unit>
<Unit NO="1">张家界</Unit>
<Unit NO="2">益阳</Unit>
</Units>
</Shop>
</Shops>
2、在初始化函数中,添加如下代码
3、然后在第一个组合框控件的消息响应函数中添加如下代码,可以使第一个改变的同时,第二个对应的改变:
xml.FindElem(_T("Shops")); xml.IntoElem(); while(xml.FindElem()) { ((CComboBox*)GetDlgItem(IDC_SHOP))->AddString(xml.GetAttrib(_T("Name"))); } ((CComboBox*)GetDlgItem(IDC_SHOP))->SetCurSel(0); xml.OutOfElem(); xml.FindElem(_T("Shops")); xml.IntoElem(); xml.ResetMainPos(); xml.FindElem(); xml.IntoElem(); xml.FindElem(_T("Units")); xml.IntoElem(); while(xml.FindElem()) { ((CComboBox*)GetDlgItem(IDC_UNIT))->AddString(xml.GetData()); } ((CComboBox*)GetDlgItem(IDC_UNIT))->SetCurSel(0); xml.OutOfElem(); xml.OutOfElem(); xml.OutOfElem();
void CDlgUnit::OnSelchangeShop()
{
// TODO: Add your control notification handler code here
((CComboBox*)GetDlgItem(IDC_UNIT))->ResetContent();
CString strShop;
int i=((CComboBox*)GetDlgItem(IDC_SHOP))->GetCurSel();
((CComboBox*)GetDlgItem(IDC_SHOP))->GetLBText(i,strShop);
CMarkup xml;//CMarkup是有关xml文件的解读,网上有文件,可以直接使用。
xml.Load(GetCurDir()+_T("123.INI"));//123.INI是xml文件的名称。
xml.ResetPos();
xml.FindChildElem();
xml.IntoElem();
xml.FindElem(_T("Shops"));
xml.IntoElem();
while(xml.FindElem()){
if(xml.GetAttrib(_T("Name"))==strShop)
{
xml.IntoElem();
xml.FindElem(_T("Units"));
xml.IntoElem();
while(xml.FindElem()){
((CComboBox*)GetDlgItem(IDC_UNIT))->AddString(xml.GetData());
}
((CComboBox*)GetDlgItem(IDC_UNIT))->SetCurSel(0);
break;
}
}
}
以上仅供参考。