承接专栏《MFC工控项目实例之十三从文件读写板卡信号名称》
在BoardTest.cpp文件中添加代码
int m_CountGetCurSel_AD[16];//索引号
UINT m_CountComboID_AD[16]=//控件ID号
{
IDC_COMBO33,
IDC_COMBO34,
IDC_COMBO35,
IDC_COMBO36,
IDC_COMBO37,
IDC_COMBO38,
IDC_COMBO39,
IDC_COMBO40,
IDC_COMBO41,
IDC_COMBO42,
IDC_COMBO43,
IDC_COMBO44,
IDC_COMBO45,
IDC_COMBO46,
IDC_COMBO47,
IDC_COMBO48,
};
CString COMB_Data_AD[17]={"- - - - - -","AD输入1","AD输入2","AD输入3","AD输入4","AD输入5","AD输入6","AD输入7","AD输入8","AD输入9","AD输入10","AD输入11","AD输入12","AD输入13","AD输入14","AD输入15","AD输入16"};
BOOL CBoardTest::OnInitDialog()
{
CDialog::OnInitDialog();
...
for ( i=0; i<16; i++)
{
for (int j=0; j<17; j++)
{
((CComboBox*)GetDlgItem(m_CountComboID_AD[i]))->AddString(COMB_Data_AD[j]);
((CComboBox*)GetDlgItem(m_CountComboID_AD[i]))->SetCurSel(0);
}
}
...
for ( m=0; m<16; m++)
{
GetPrivateProfileString("AD输入",COMB_Data_AD[m+1],NULL,strRead[m].GetBuffer(20),20,strFilePath);
strReadId[m]=_ttoi(strRead[m]);
if(strReadId[m]!=-1)
{
((CComboBox*)GetDlgItem(m_CountComboID_AD[strReadId[m]]))->SetWindowText(COMB_Data_AD[m+1]);
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBoardTest::OnButton3()
{
...
for ( m=1; m<17; m++)
{
WritePrivateProfileString("AD输入",COMB_Data_AD[m],"-1",strFilePath);
}
for ( n=0; n<16; n++)
{
((CComboBox*)GetDlgItem(m_CountComboID_AD[n]))->GetWindowText(strTemp[n]);//当前内容
NO_Combox[n].Format(_T("%d"), n);
if (strTemp[n]!="------")
{
WritePrivateProfileString("AD输入",strTemp[n],NO_Combox[n],strFilePath);
}
}
Sleep(500);
EndDialog(IDD_DIALOG_BOA_TEST);
}
运行程序