ResizableState.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // This file is part of ResizableLib
  4. // https://github.com/ppescher/resizablelib
  5. //
  6. // Copyright (C) 2000-2015 by Paolo Messina
  7. // mailto:ppescher@hotmail.com
  8. //
  9. // The contents of this file are subject to the Artistic License 2.0
  10. // http://opensource.org/licenses/Artistic-2.0
  11. //
  12. // If you find this code useful, credits would be nice!
  13. //
  14. /////////////////////////////////////////////////////////////////////////////
  15. /*!
  16. * @file
  17. * @brief Implementation of the CResizableState class.
  18. */
  19. #include "stdafx.h"
  20. #include "ResizableState.h"
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char THIS_FILE[]=__FILE__;
  24. #define new DEBUG_NEW
  25. #endif
  26. //////////////////////////////////////////////////////////////////////
  27. // Construction/Destruction
  28. //////////////////////////////////////////////////////////////////////
  29. CResizableState::CResizableState()
  30. {
  31. m_sStorePath = m_sDefaultStorePath;
  32. }
  33. CResizableState::~CResizableState()
  34. {
  35. }
  36. // static intializer must be called before user code
  37. #pragma warning(disable:4073)
  38. #pragma init_seg(lib)
  39. CString CResizableState::m_sDefaultStorePath(_T("ResizableState"));
  40. /*!
  41. * Static function to set the default path used to store state information.
  42. * This path is used to initialize all the instances of this class.
  43. * @sa GetDefaultStateStore GetStateStore SetStateStore
  44. *
  45. * @param szPath String that specifies the new path to be set
  46. */
  47. void CResizableState::SetDefaultStateStore(LPCTSTR szPath)
  48. {
  49. m_sDefaultStorePath = szPath;
  50. }
  51. /*!
  52. * Static function to retrieve the default path used to store state
  53. * information.
  54. * This path is used to initialize all the instances of this class.
  55. * @sa SetDefaultStateStore GetStateStore SetStateStore
  56. *
  57. * @return The return value is a string that specifies the current path
  58. */
  59. LPCTSTR CResizableState::GetDefaultStateStore()
  60. {
  61. return m_sDefaultStorePath;
  62. }
  63. /*!
  64. * This function sets the path used to store state information by
  65. * the current instance of the class.
  66. * @sa GetStateStore GetDefaultStateStore SetDefaultStateStore
  67. *
  68. * @param szPath String that specifies the new path to be set
  69. */
  70. void CResizableState::SetStateStore(LPCTSTR szPath)
  71. {
  72. m_sStorePath = szPath;
  73. }
  74. /*!
  75. * This function retrieves the path used to store state information by
  76. * the current instance of the class.
  77. * @sa SetStateStore GetDefaultStateStore SetDefaultStateStore
  78. *
  79. * @return The return value is a string that specifies the current path
  80. */
  81. LPCTSTR CResizableState::GetStateStore()
  82. {
  83. return m_sStorePath;
  84. }
  85. /*!
  86. * This function writes state information and associates it with some
  87. * identification text for later retrieval.
  88. * The base implementation uses the application profile to persist state
  89. * information, but this function can be overridden to implement
  90. * different methods.
  91. *
  92. * @param szId String that identifies the stored settings
  93. * @param szState String that represents the state information to store
  94. *
  95. * @return The return value is @a TRUE if settings have been successfully
  96. * stored, @a FALSE otherwise.
  97. */
  98. BOOL CResizableState::WriteState(LPCTSTR szId, LPCTSTR szState)
  99. {
  100. return AfxGetApp()->WriteProfileString(GetStateStore(), szId, szState);
  101. }
  102. /*!
  103. * This function reads state information previously associated with some
  104. * identification text.
  105. * The base implementation uses the application profile to persist state
  106. * information, but this function can be overridden to implement
  107. * different methods.
  108. *
  109. * @param szId String that identifies the stored settings
  110. * @param rsState String to be filled with the retrieved state information
  111. *
  112. * @return The return value is @a TRUE if settings have been successfully
  113. * retrieved, @a FALSE otherwise.
  114. */
  115. BOOL CResizableState::ReadState(LPCTSTR szId, CString &rsState)
  116. {
  117. rsState = AfxGetApp()->GetProfileString(GetStateStore(), szId);
  118. return !rsState.IsEmpty();
  119. }