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

承接专栏《MFC工控项目实例之十二板卡测试信号输出界面》

1、在BoardTest.h文件中添加代码

cpp 复制代码
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文件中添加代码

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

运行程序

相关推荐
众少成多积小致巨17 小时前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
clint4565 天前
C++进阶(1)——前景提要
c++
夜悊5 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴5 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0016 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾6 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
один but you6 天前
constexpr函数
c++
凡人叶枫6 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++
凡人叶枫6 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++
小胖xiaopangss6 天前
BRpc使用
c++·rpc