欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > MFC工控项目实例之十三从文件读写板卡信号名称

MFC工控项目实例之十三从文件读写板卡信号名称

2024/10/25 12:27:47 来源:https://blog.csdn.net/weixin_42350092/article/details/142110666  浏览:    关键词:MFC工控项目实例之十三从文件读写板卡信号名称

承接专栏《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);
}

运行程序在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com