程序说明:本程序基于前期我的博客文章《MFC多个组合框数据项位置实时写入ini文件实例》
在《MFC多个组合框数据项位置实时写入ini文件实例》的资源视图对话框上再添加一个从INI文件读取按钮。
从INI文件读取按钮单击事件代码如下
void CCombTestDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CString strRead[16];
int strReadId[16];
char strBuff[256];
CString strFilePath;
strFilePath=GetCurrentDirectory(256,strBuff); //获取当前路径
strFilePath.Format("%s//Test.ini",strBuff);
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]);
}
}
}
运行程序点击INI文件读取按钮,组合框当前数据项显示的位置将从test.ini文件读取。
源码下载
https://blog.youkuaiyun.com/weixin_42350092/article/details/130188503?spm=1001.2014.3001.5502