工控编程吧
标题: 上位机MFC如何获得INI文件指定段的全部键名和键值 [打印本页]
作者: qq263946146 时间: 2019-8-2 16:10
标题: 上位机MFC如何获得INI文件指定段的全部键名和键值
对应的实现函数为GetPrivateProfileSection。例如例程中的点击函数使用的样子。
int nBufferSize = GetPrivateProfileSection(strSectionName, szBuffer, 65536, m_strFileName);
- void CGkbc8Dlg::OnButton2()
- {
- CListCtrl* pList = (CListCtrl*)GetDlgItem(IDC_LIST);
- pList->DeleteAllItems();
- TCHAR szKey[1024] = {0};
- CString strKey = _T("");
- CString strKeyName = _T("");
- CString strKeyValue = _T("");
- TCHAR szBuffer[65536] = {0};
- CString strSectionName = _T("");
- GetDlgItemText(IDC_TEXT2, strSectionName);
- //获得INI文件指定段的全部键名和键值
- int nBufferSize = GetPrivateProfileSection(strSectionName, szBuffer, 65536, m_strFileName);
- int nItem = 0;
- for (int n = 0, i = 0; n < nBufferSize; n++)
- {
- if (szBuffer[n] == 0)
- {
- szKey[i] = 0;
- strKey = szKey;
- strKeyName = strKey.Left(strKey.Find('='));
- strKeyValue = strKey.Mid(strKey.Find('=') + 1);
- pList->InsertItem(nItem, strKeyName);
- pList->SetItemText(nItem, 1, strKeyValue);
- i = 0;
- nItem++;
- }
- else
- {
- szKey[i] = szBuffer[n];
- i++;
- }
- }
- }
复制代码
(, 下载次数: 1)