int CHLD_TERMINATEDlg::OnGenerateIniFile() // 生成配置文件
{
// TODO: Add your control notification handler code here
// 打开Ini文件,按编辑框中的内容写入INI文件
CStdioFile file;
CString strSection, strKey, strKeyValue, m_strPath;
if (m_sUpFilePath == "")
{
MessageBox("请选择程序文件!", "提示", MB_OK | MB_ICONWARNING);
return FALSE;
}
// if (m_sReleaseDate.GetLength() < 6)
// {
// MessageBox("请输入6位的终端软件发布日期:日月年!", "提示", MB_OK | MB_ICONWARNING);
// return FALSE;
// }
// if (m_sTermArea.GetLength() < 4)
// {
// MessageBox("请输入4位区号码!", "提示", MB_OK | MB_ICONWARNING);
// return FALSE;
// }
UpdateData(TRUE);
gProfileInfo.packetlen = atoi(m_sPacketLen); // 帧长度,由界面设置
if (gProfileInfo.lFilelen % gProfileInfo.packetlen)
gProfileInfo.nPageNum = gProfileInfo.lFilelen / gProfileInfo.packetlen + 1;
else
gProfileInfo.nPageNum = gProfileInfo.lFilelen / gProfileInfo.packetlen;
m_ctrlProgBar.SetRange(0, gProfileInfo.nPageNum);
strcpy(gProfileInfo.fileName, (LPCSTR)m_sFileName);
strcpy(gProfileInfo.softVersion, (LPCSTR)m_sSoftVersion);
strcpy(gProfileInfo.confInfoCode, (LPCSTR)m_sCapacityCode);
strcpy(gProfileInfo.factoryCode, (LPCSTR)m_sFactoryCode);
strcpy(gProfileInfo.deviceNo, (LPCSTR)m_sDeviceCode);
m_strPath = ".\\windy.ini"; // 生成配置文件
if (file.Open(m_strPath, CFile::modeCreate | CFile::typeText | CFile::modeReadWrite))
{
file.WriteString("[config]\r\n");
file.Close();
}
else
MessageBox("文件生成失败!", "错误", MB_ICONERROR | MB_OK);
strSection = "config";
strKey = "trans_len";
strKeyValue.Format("%d", gProfileInfo.packetlen);
WritePrivateProfileString((LPCTSTR)strSection, (LPCTSTR)strKey, (LPCTSTR)strKeyValue, (LPCTSTR)m_strPath);
strKey = "file_name";
strKeyValue.Format("%s", gProfileInfo.fileName);
WritePrivateProfileString((LPCTSTR)strSection, (LPCTSTR)strKey, (LPCTSTR)strKeyValue, (LPCTSTR)m_strPath);
strKey = "file_crc";
strKeyValue.Format("%02X%02X", gProfileInfo.fileCrc[0] & 0XFF, gProfileInfo.fileCrc[1] & 0XFF);
WritePrivateProfileString((LPCTSTR)strSection, (LPCTSTR)strKey, (LPCTSTR)strKeyValue, (LPCTSTR)m_strPath);
strKey = "file_info";
// gProfileInfo.factoryCode[4] = 0;
// gProfileInfo.deviceNo[8] = 0;
// gProfileInfo.softVersion[4] = 0;
// gProfileInfo.releaseDate[3] = 0;
// gProfileInfo.confInfoCode[11] = 0;
// zyh 2011-10-10 begin
memcpy(gProfileInfo.factoryCode,
m_sFactoryCode, 4);
gProfileInfo.factoryCode[4] = 0;
memcpy(gProfileInfo.deviceNo,
m_sDeviceCode, 8);
gProfileInfo.deviceNo[8] = 0;
memcpy(gProfileInfo.softVersion,
m_sSoftVersion, 4);
gProfileInfo.softVersion[4] = 0;
//====zyh 2011-10-10 begin
CString strTemp = m_sReleaseDate;
char temp[16];
strcpy(temp, strTemp.Mid(strTemp.GetLength() - 6, 2));
char *stopstring = temp + 2;
gProfileInfo.releaseDate[0] = strtol(temp, &stopstring, 16);
strcpy(temp, strTemp.Mid(strTemp.GetLength() - 4, 2));
stopstring = temp + 2;
gProfileInfo.releaseDate[1] = strtol(temp, &stopstring, 16);
strcpy(temp, strTemp.Mid(strTemp.GetLength() - 2, 2));
stopstring = temp + 2;
gProfileInfo.releaseDate[2] = strtol(temp, &stopstring, 16);
gProfileInfo.releaseDate[3] = 0;
//====zyh 2011-10-10 end
memcpy(gProfileInfo.confInfoCode,
m_sCapacityCode, 11);
gProfileInfo.confInfoCode[11] = 0;
// zyh 2011-10-10 end
strKeyValue.Format("%s%s%s%s%s", gProfileInfo.factoryCode, gProfileInfo.deviceNo, gProfileInfo.softVersion, gProfileInfo.releaseDate, gProfileInfo.confInfoCode);
WritePrivateProfileString((LPCTSTR)strSection, (LPCTSTR)strKey, (LPCTSTR)strKeyValue, (LPCTSTR)m_strPath);
strKey = "file_len";
strKeyValue.Format("%d", gProfileInfo.lFilelen);
WritePrivateProfileString((LPCTSTR)strSection, (LPCTSTR)strKey, (LPCTSTR)strKeyValue, (LPCTSTR)m_strPath);
strKey = "file_mes";
strKeyValue = gProfileInfo.fileMess;
WritePrivateProfileString((LPCTSTR)strSection, (LPCTSTR)strKey, (LPCTSTR)strKeyValue, (LPCTSTR)m_strPath);
strKey = "file_israr";
strKeyValue = "0";
WritePrivateProfileString((LPCTSTR)strSection, (LPCTSTR)strKey, (LPCTSTR)strKeyValue, (LPCTSTR)m_strPath);
// MessageBox("配置文件生成完毕!", "提示", MB_OK | MB_ICONWARNING);
m_tabstyle.EnableWindow(TRUE);
m_ctrl_Com_Port.EnableWindow(TRUE);
m_ctrl_Com_Baud.EnableWindow(TRUE);
m_ctrl_Local_Port.EnableWindow(TRUE);
m_btnOpen.EnableWindow(TRUE);
return TRUE;
}请详细解释一下每一行代码
最新发布