ResizableFrame.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // ResizableFrame.cpp : implementation file
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. //
  5. // This file is part of ResizableLib
  6. // https://github.com/ppescher/resizablelib
  7. //
  8. // Copyright (C) 2000-2015 by Paolo Messina
  9. // mailto:ppescher@hotmail.com
  10. //
  11. // The contents of this file are subject to the Artistic License 2.0
  12. // http://opensource.org/licenses/Artistic-2.0
  13. //
  14. // If you find this code useful, credits would be nice!
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "ResizableFrame.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CResizableFrame
  26. IMPLEMENT_DYNCREATE(CResizableFrame, CFrameWnd)
  27. CResizableFrame::CResizableFrame()
  28. {
  29. m_bEnableSaveRestore = FALSE;
  30. m_bRectOnly = FALSE;
  31. }
  32. CResizableFrame::~CResizableFrame()
  33. {
  34. }
  35. BEGIN_MESSAGE_MAP(CResizableFrame, CFrameWnd)
  36. //{{AFX_MSG_MAP(CResizableFrame)
  37. ON_WM_GETMINMAXINFO()
  38. ON_WM_DESTROY()
  39. ON_WM_NCCREATE()
  40. ON_WM_WINDOWPOSCHANGING()
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CResizableFrame message handlers
  45. void CResizableFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  46. {
  47. MinMaxInfo(lpMMI);
  48. CView* pView = GetActiveView();
  49. if (pView == NULL)
  50. return;
  51. ChainMinMaxInfo(lpMMI, this, pView);
  52. }
  53. // NOTE: this must be called after setting the layout
  54. // to have the view and its controls displayed properly
  55. BOOL CResizableFrame::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
  56. {
  57. m_sSection = pszSection;
  58. m_bEnableSaveRestore = TRUE;
  59. m_bRectOnly = bRectOnly;
  60. // restore immediately
  61. return LoadWindowRect(pszSection, bRectOnly);
  62. }
  63. void CResizableFrame::OnDestroy()
  64. {
  65. if (m_bEnableSaveRestore)
  66. SaveWindowRect(m_sSection, m_bRectOnly);
  67. // reset instance data
  68. RemoveAllAnchors();
  69. ResetAllRects();
  70. m_bEnableSaveRestore = FALSE;
  71. CFrameWnd::OnDestroy();
  72. }
  73. BOOL CResizableFrame::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
  74. {
  75. if (!CFrameWnd::OnNcCreate(lpCreateStruct))
  76. return FALSE;
  77. MakeResizable(lpCreateStruct);
  78. return TRUE;
  79. }
  80. LRESULT CResizableFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  81. {
  82. if (message != WM_NCCALCSIZE || wParam == 0)
  83. return CFrameWnd::WindowProc(message, wParam, lParam);
  84. // specifying valid rects needs controls already anchored
  85. LRESULT lResult = 0;
  86. HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
  87. lResult = CFrameWnd::WindowProc(message, wParam, lParam);
  88. HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
  89. return lResult;
  90. }
  91. // TODO: implement this in CResizableMinMax
  92. // We definitely need pluggable message handlers ala WTL!
  93. void CResizableFrame::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
  94. {
  95. if ((lpwndpos->flags & (SWP_NOSIZE|SWP_NOMOVE)) != (SWP_NOSIZE|SWP_NOMOVE))
  96. CFrameWnd::OnWindowPosChanging(lpwndpos);
  97. }