ResizableFrame.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // ResizableFrame.cpp : implementation file
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Copyright (C) 2000-2002 by Paolo Messina
  6. // (http://www.geocities.com/ppescher - ppescher@yahoo.com)
  7. //
  8. // The contents of this file are subject to the Artistic License (the "License").
  9. // You may not use this file except in compliance with the License.
  10. // You may obtain a copy of the License at:
  11. // http://www.opensource.org/licenses/artistic-license.html
  12. //
  13. // If you find this code useful, credits would be nice!
  14. //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "stdafx.h"
  17. #include "ResizableFrame.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CResizableFrame
  25. IMPLEMENT_DYNCREATE(CResizableFrame, CFrameWnd)
  26. CResizableFrame::CResizableFrame()
  27. {
  28. m_bEnableSaveRestore = FALSE;
  29. }
  30. CResizableFrame::~CResizableFrame()
  31. {
  32. }
  33. BEGIN_MESSAGE_MAP(CResizableFrame, CFrameWnd)
  34. //{{AFX_MSG_MAP(CResizableFrame)
  35. ON_WM_GETMINMAXINFO()
  36. ON_WM_DESTROY()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CResizableFrame message handlers
  41. void CResizableFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  42. {
  43. MinMaxInfo(lpMMI);
  44. CView* pView = GetActiveView();
  45. if (pView == NULL)
  46. return;
  47. // get the extra size from view to frame
  48. CRect rectClient, rectWnd;
  49. GetWindowRect(rectWnd);
  50. RepositionBars(0, 0xFFFF, AFX_IDW_PANE_FIRST, reposQuery, rectClient);
  51. CSize sizeExtra = rectWnd.Size() - rectClient.Size();
  52. // ask the view for track size
  53. MINMAXINFO mmiView = *lpMMI;
  54. pView->SendMessage(WM_GETMINMAXINFO, 0, (LPARAM)&mmiView);
  55. mmiView.ptMaxTrackSize = sizeExtra + mmiView.ptMaxTrackSize;
  56. mmiView.ptMinTrackSize = sizeExtra + mmiView.ptMinTrackSize;
  57. // min size is the largest
  58. lpMMI->ptMinTrackSize.x = __max(lpMMI->ptMinTrackSize.x,
  59. mmiView.ptMinTrackSize.x);
  60. lpMMI->ptMinTrackSize.y = __max(lpMMI->ptMinTrackSize.y,
  61. mmiView.ptMinTrackSize.y);
  62. // max size is the shortest
  63. lpMMI->ptMaxTrackSize.x = __min(lpMMI->ptMaxTrackSize.x,
  64. mmiView.ptMaxTrackSize.x);
  65. lpMMI->ptMaxTrackSize.y = __min(lpMMI->ptMaxTrackSize.y,
  66. mmiView.ptMaxTrackSize.y);
  67. }
  68. // NOTE: this must be called after setting the layout
  69. // to have the view and its controls displayed properly
  70. BOOL CResizableFrame::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
  71. {
  72. m_sSection = pszSection;
  73. m_bEnableSaveRestore = TRUE;
  74. m_bRectOnly = bRectOnly;
  75. // restore immediately
  76. return LoadWindowRect(pszSection, bRectOnly);
  77. }
  78. void CResizableFrame::OnDestroy()
  79. {
  80. if (m_bEnableSaveRestore)
  81. SaveWindowRect(m_sSection, m_bRectOnly);
  82. CFrameWnd::OnDestroy();
  83. }