// Config.cpp: implementation of the CConfig class. // ////////////////////////////////////////////////////////////////////// #include "pch.h" #include #include "Config.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CConfig CConfig::s_Config; CConfig::CConfig() { } BOOL CConfig::SaveSetting() { BOOL bRet=FALSE; bRet=SaveToINI(); return bRet; } BOOL CConfig::LoadFromINI() { TCHAR szData[_MAX_PATH]; memset(szData, 0, sizeof(szData)); CString strIni = GetAppPath() + _T("config.ini"); GetPrivateProfileString(_T("Set"), _T("Txt"), _T(""), szData, sizeof(szData), strIni); m_strTxt = szData; GetPrivateProfileString(_T("Set"), _T("Pdf"), _T(""), szData, sizeof(szData), strIni); m_strPdf = szData; GetPrivateProfileString(_T("Set"), _T("Mode"), _T(""), szData, sizeof(szData), strIni); m_strMode = szData; GetPrivateProfileString(_T("Set"), _T("Img"), _T(""), szData, sizeof(szData), strIni); m_strImg = szData; GetPrivateProfileString(_T("Set"), _T("Cut"), _T(""), szData, sizeof(szData), strIni); m_strCut = szData; return TRUE; } BOOL CConfig::SaveToINI() { TCHAR sTmp[64] = {0}; std::string strPwd; CString strTmp = _T(""); CString strIni = GetAppPath() + _T("config.ini"); WritePrivateProfileString(_T("Set"), _T("Txt"), m_strTxt, strIni); WritePrivateProfileString(_T("Set"), _T("Pdf"), m_strPdf, strIni); WritePrivateProfileString(_T("Set"), _T("Mode"), m_strMode, strIni); WritePrivateProfileString(_T("Set"), _T("Img"), m_strImg, strIni); WritePrivateProfileString(_T("Set"), _T("Cut"), m_strCut, strIni); return TRUE; } CString CConfig::GetAppPath() { CString strAppPath; TCHAR *pBuf=strAppPath.GetBuffer(_MAX_PATH); GetModuleFileName(AfxGetApp()->m_hInstance,pBuf,_MAX_PATH); TCHAR* pch=_tcsrchr(pBuf,_T('\\')); if(pch) *(pch+1)=0; else _tcscat(pBuf,_T("\\")); strAppPath.ReleaseBuffer(); return strAppPath; }