读取配置文件
CString strSection =_T("ServerIP");
CString strSectionKey = _T("IP");
CString strValue = _T("");
charstrBuffer[256];
CString strFilePath = ".\\Config.ini";
GetPrivateProfileString(strSection,strSectionKey,NULL,strBuffer,80,strFilePath);
m_ServerIP = strBuffer;
strSectionKey = "Port";
GetPrivateProfileString(strSection,strSectionKey,NULL,strBuffer,80,strFilePath);
m_nPort = atoi(strBuffer);
写配置文件
CString strSection =_T("ServerIP") ;
CString strSectionKey = _T("IP");
CString strValue = _T("");
charstrBuff[256];
CString strFilePath = ".\\Config.ini";
GetDlgItem(IDC_SERVERIP)->GetWindowText(strValue);
if(!WritePrivateProfileString(strSection,strSectionKey,strValue,strFilePath))
{
MessageBox("无法写入配置文件","警告");
return;
}
m_eProt.GetWindowText(strValue);
strSectionKey = "Port";
if(!WritePrivateProfileString(strSection,strSectionKey,strValue,strFilePath))
{
MessageBox("无法写入配置文件","警告");
return;
}
MessageBox("配置成功","提示");