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);
}

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

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

兵哥工控

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值