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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章