IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    IniFileGetValue,IniFileSetValue

    天下发表于 2015-07-10 09:25:00
    love 0


    Code highlighting produced by Actipro CodeHighlighter (freeware)
    http://www.CodeHighlighter.com/

    static CString GetAppDirectory(){ CString sPath; GetModuleFileName(NULL,sPath.GetBuffer(MAX_PATH+1),MAX_PATH); //GetCurrentDirectory(MAX_PATH,sPath.GetBuffer(MAX_PATH+1)); sPath.ReleaseBuffer (); int nPos; nPos=sPath.ReverseFind ('\\'); sPath=sPath.Left(nPos+1); return sPath;}static CString IniFileGetValue(const CString& strFileName,const CString& strKeyPath,const CString& strDefault=""){ CStringArray strKeys; CString strValue; int last_pos = 0; int pos; int new_pos; CString strKey; while (1) { pos = strKeyPath.Find("/",last_pos); new_pos = pos; if (pos==-1) new_pos = strKeyPath.GetLength(); strKey = strKeyPath.Mid(last_pos,new_pos - last_pos); last_pos = pos+1; if (!strKey.IsEmpty()) strKeys.Add(strKey); if (pos==-1) break; } if (strKeys.GetSize()!=2) return strDefault; GetPrivateProfileString(strKeys[0],strKeys[1],0,strValue.GetBuffer(4096),4095,strFileName); strValue.ReleaseBuffer(); if (strValue.IsEmpty()) return strDefault; return strValue;}static BOOL IniFileSetValue(const CString& strFileName,const CString& strKeyPath,const CString& strValue){ CStringArray strKeys; int last_pos = 0; int pos; int new_pos; CString strKey; while (1) { pos = strKeyPath.Find("/",last_pos); new_pos = pos; if (pos==-1) new_pos = strKeyPath.GetLength(); strKey = strKeyPath.Mid(last_pos,new_pos - last_pos); last_pos = pos+1; if (!strKey.IsEmpty()) strKeys.Add(strKey); if (pos==-1) break; } if (strKeys.GetSize()!=2) return FALSE; return WritePrivateProfileString(strKeys[0],strKeys[1],strValue,strFileName);}天下2015-07-10 17:25发表评论


沪ICP备19023445号-2号
友情链接