承接专栏《MFC工控项目实例之十二板卡测试信号输出界面》
1、在BoardTest.h文件中添加代码
class CBoardTest : public CDialog
{
public:
CBoardTest(CWnd* pParent = NULL); // standard constructor
...
CString NO_Combox[16];
CString strTemp[16];//数据项名称
CString strRead[16];
int strReadId[16];
char strBuff[256];
CString m_Path;
CString strFilePath;
...
}
2、在BoardTest.cpp文件中添加代码
CBoardTest::CBoardTest(CWnd* pParent /*=NULL*/)
: CDialog(CBoardTest::IDD, pParent)
{
TCHAR exeFullPath[MAX_PATH];
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
m_Path = exeFullPath;
for(int i = m_Path.GetLength() - 1; i > 0 ; i --)
{
if(m_Path.GetAt(i) == '\\')
break;
}
SetCurrentDirectory(m_Path);
m_Path = m_Path.Left(i);
strFilePath= m_Path + "\\Test.ini";
}
BOOL CBoardTest::OnInitDialog()
{
CDialog::OnInitDialog();
...
for (int m=0; m<16; m++)
{
GetPrivateProfileString("输入信号",COMB_Data[m+1],NULL,strRead[m].GetBuffer(20),20,strFilePath);
strReadId[m]=_ttoi(strRead[m]);
if(strReadId[m]!=-1)
{
((CComboBox*)GetDlgItem(m_CountComboID[strReadId[m]]))->SetWindowText(COMB_Data[m+1]);
}
}
for ( m=0; m<16; m++)
{
GetPrivateProfileString("输出信号",COMB_Data_O[m+1],NULL,strRead[m].GetBuffer(20),20,strFilePath);
strReadId[m]=_ttoi(strRead[m]);
if(strReadId[m]!=-1)
{
((CComboBox*)GetDlgItem(m_CountComboID_O[strReadId[m]]))->SetWindowText(COMB_Data_O[m+1]);
}
}
return TRUE;
}
void CBoardTest::OnButton3()
{
for (int m=1; m<17; m++)
{
WritePrivateProfileString("输入信号",COMB_Data[m],"-1",strFilePath);
}
for (int n=0; n<16; n++)
{
((CComboBox*)GetDlgItem(m_CountComboID[n]))->GetWindowText(strTemp[n]);//当前内容
NO_Combox[n].Format(_T("%d"), n);
if (strTemp[n]!="------")
{
WritePrivateProfileString("输入信号",strTemp[n],NO_Combox[n],strFilePath);
}
}
for ( m=1; m<17; m++)
{
WritePrivateProfileString("输出信号",COMB_Data_O[m],"-1",strFilePath);
}
for ( n=0; n<16; n++)
{
((CComboBox*)GetDlgItem(m_CountComboID_O[n]))->GetWindowText(strTemp[n]);//当前内容
NO_Combox[n].Format(_T("%d"), n);
if (strTemp[n]!="------")
{
WritePrivateProfileString("输出信号",strTemp[n],NO_Combox[n],strFilePath);
}
}
Sleep(500);
EndDialog(IDD_DIALOG_BOA_TEST);
}
运行程序