VC技术篇之配置文件读写

读取配置文件

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("配置成功","提示");

 

发布了37 篇原创文章 · 获赞 5 · 访问量 5万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章