Config.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Config.cpp: implementation of the CConfig class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "pch.h"
  5. #include <atlbase.h>
  6. #include "Config.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CConfig CConfig::s_Config;
  16. CConfig::CConfig()
  17. {
  18. }
  19. BOOL CConfig::SaveSetting()
  20. {
  21. BOOL bRet=FALSE;
  22. bRet=SaveToINI();
  23. return bRet;
  24. }
  25. BOOL CConfig::LoadFromINI()
  26. {
  27. TCHAR szData[_MAX_PATH];
  28. memset(szData, 0, sizeof(szData));
  29. CString strIni = GetAppPath() + _T("config.ini");
  30. GetPrivateProfileString(_T("Set"), _T("Txt"), _T(""), szData, sizeof(szData), strIni);
  31. m_strTxt = szData;
  32. GetPrivateProfileString(_T("Set"), _T("Pdf"), _T(""), szData, sizeof(szData), strIni);
  33. m_strPdf = szData;
  34. GetPrivateProfileString(_T("Set"), _T("Mode"), _T(""), szData, sizeof(szData), strIni);
  35. m_strMode = szData;
  36. GetPrivateProfileString(_T("Set"), _T("Img"), _T(""), szData, sizeof(szData), strIni);
  37. m_strImg = szData;
  38. GetPrivateProfileString(_T("Set"), _T("Cut"), _T(""), szData, sizeof(szData), strIni);
  39. m_strCut = szData;
  40. return TRUE;
  41. }
  42. BOOL CConfig::SaveToINI()
  43. {
  44. TCHAR sTmp[64] = {0};
  45. std::string strPwd;
  46. CString strTmp = _T("");
  47. CString strIni = GetAppPath() + _T("config.ini");
  48. WritePrivateProfileString(_T("Set"), _T("Txt"), m_strTxt, strIni);
  49. WritePrivateProfileString(_T("Set"), _T("Pdf"), m_strPdf, strIni);
  50. WritePrivateProfileString(_T("Set"), _T("Mode"), m_strMode, strIni);
  51. WritePrivateProfileString(_T("Set"), _T("Img"), m_strImg, strIni);
  52. WritePrivateProfileString(_T("Set"), _T("Cut"), m_strCut, strIni);
  53. return TRUE;
  54. }
  55. CString CConfig::GetAppPath()
  56. {
  57. CString strAppPath;
  58. TCHAR *pBuf=strAppPath.GetBuffer(_MAX_PATH);
  59. GetModuleFileName(AfxGetApp()->m_hInstance,pBuf,_MAX_PATH);
  60. TCHAR* pch=_tcsrchr(pBuf,_T('\\'));
  61. if(pch)
  62. *(pch+1)=0;
  63. else
  64. _tcscat(pBuf,_T("\\"));
  65. strAppPath.ReleaseBuffer();
  66. return strAppPath;
  67. }