ResizableSheetState.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 CResizableSheetState class.
  18. */
  19. #include "stdafx.h"
  20. #include "ResizableSheetState.h"
  21. //////////////////////////////////////////////////////////////////////
  22. // Construction/Destruction
  23. //////////////////////////////////////////////////////////////////////
  24. CResizableSheetState::CResizableSheetState()
  25. {
  26. }
  27. CResizableSheetState::~CResizableSheetState()
  28. {
  29. }
  30. // used to save/restore active page
  31. // either in the registry or a private .INI file
  32. // depending on your application settings
  33. #define ACTIVEPAGE_ENT _T("ActivePage")
  34. /*!
  35. * This function saves the current property sheet active page using the base
  36. * class persist method.
  37. * @sa CResizableState::WriteState
  38. *
  39. * @param pszName String that identifies stored settings
  40. *
  41. * @return Returns @a TRUE if successful, @a FALSE otherwise
  42. */
  43. BOOL CResizableSheetState::SavePage(LPCTSTR pszName)
  44. {
  45. // saves active page index, or the initial page if problems
  46. // cannot use GetActivePage, because it always fails
  47. CPropertySheet* pSheet = DYNAMIC_DOWNCAST(CPropertySheet, GetResizableWnd());
  48. if (pSheet == NULL)
  49. return FALSE;
  50. int page = pSheet->m_psh.nStartPage;
  51. CTabCtrl *pTab = pSheet->GetTabControl();
  52. if (pTab != NULL)
  53. page = pTab->GetCurSel();
  54. if (page < 0)
  55. page = pSheet->m_psh.nStartPage;
  56. CString data, id;
  57. _itot(page, data.GetBuffer(10), 10);
  58. id = CString(pszName) + ACTIVEPAGE_ENT;
  59. return WriteState(id, data);
  60. }
  61. /*!
  62. * This function loads the active page using the base class persist method.
  63. * @sa CResizableState::ReadState
  64. *
  65. * @param pszName String that identifies stored settings
  66. *
  67. * @return Returns @a TRUE if successful, @a FALSE otherwise
  68. */
  69. BOOL CResizableSheetState::LoadPage(LPCTSTR pszName)
  70. {
  71. // restore active page, zero (the first) if not found
  72. CString data, id;
  73. id = CString(pszName) + ACTIVEPAGE_ENT;
  74. if (!ReadState(id, data))
  75. return FALSE;
  76. int page = _ttoi(data);
  77. CPropertySheet* pSheet = DYNAMIC_DOWNCAST(CPropertySheet, GetResizableWnd());
  78. if (pSheet != NULL)
  79. return pSheet->SetActivePage(page);
  80. return FALSE;
  81. }