Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.0 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: Settings.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of Settings.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "Settings.h"
  16. #include "..\..\lglib\lgaux.h"
  17. #include "..\..\LgLib\Version.h"
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[]=__FILE__;
  21. #define new DEBUG_NEW
  22. #endif
  23. CSettings::CSettings()
  24. {
  25. m_hKey = NULL;
  26. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSettings::CSettings") );
  27. }
  28. CSettings::~CSettings()
  29. {
  30. Destroy();
  31. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSettings::~CSettings") );
  32. }
  33. BOOL CSettings::Create( LPCTSTR pKeyName )
  34. {
  35. Destroy();
  36. TCHAR pPath[MAX_PATH];
  37. ::PathCombine( pPath, _T("Software"), pKeyName );
  38. if( ::RegCreateKey( HKEY_CURRENT_USER, pPath, &m_hKey ) != ERROR_SUCCESS )
  39. {
  40. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSettings::Create"), _T("RegCreateKey failed") );
  41. return FALSE;
  42. }
  43. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSettings::Create"), _T("Succeeded") );
  44. return TRUE;
  45. }
  46. void CSettings::Destroy()
  47. {
  48. if( m_hKey )
  49. {
  50. ::RegFlushKey( m_hKey );
  51. ::RegCloseKey( m_hKey );
  52. m_hKey = NULL;
  53. }
  54. }
  55. BOOL CSettings::Load( LPCTSTR pSettingName, PVOID pData, INT nSize )
  56. {
  57. if( !m_hKey )
  58. return FALSE;
  59. if( !pSettingName || !pData || !nSize )
  60. return FALSE;
  61. return ::RegQueryValueEx( m_hKey, pSettingName, NULL, NULL, (PBYTE)pData, (PDWORD)&nSize ) == ERROR_SUCCESS;
  62. }
  63. BOOL CSettings::Save( LPCTSTR pSettingName, PVOID pData, INT nSize )
  64. {
  65. if( !m_hKey )
  66. return FALSE;
  67. if( !pSettingName || !pData || !nSize )
  68. return FALSE;
  69. return ::RegSetValueEx( m_hKey, pSettingName, 0UL, REG_BINARY, (PBYTE)pData, nSize ) == ERROR_SUCCESS;
  70. }
  71. BOOL CSettings::Save( LPCTSTR pSettingName, LPRECT pRect )
  72. {
  73. return Save( pSettingName, pRect, sizeof(RECT) );
  74. }
  75. BOOL CSettings::Load( LPCTSTR pSettingName, LPRECT pRect )
  76. {
  77. return Load( pSettingName, pRect, sizeof(RECT) );
  78. }
  79. BOOL CSettings::Load( LPCTSTR pSettingName, PINT pValue )
  80. {
  81. return Load( pSettingName, pValue, sizeof(INT) );
  82. }
  83. BOOL CSettings::Save( LPCTSTR pSettingName, INT nValue )
  84. {
  85. return Save( pSettingName, &nValue, sizeof(INT) );
  86. }
  87. BOOL CSettings::Load( LPCTSTR pSettingName, double* pValue )
  88. {
  89. return Load( pSettingName, pValue, sizeof(double) );
  90. }
  91. BOOL CSettings::Save( LPCTSTR pSettingName, double dValue )
  92. {
  93. return Save( pSettingName, &dValue, sizeof(double) );
  94. }
  95. BOOL CSettings::Save( LPCTSTR pSettingName, CLgDRect *pRect )
  96. {
  97. return Save( pSettingName, pRect, sizeof(CLgDRect) );
  98. }
  99. BOOL CSettings::Load( LPCTSTR pSettingName, CLgDRect *pRect )
  100. {
  101. return Load( pSettingName, pRect, sizeof(CLgDRect) );
  102. }