ResizableMDIFrame.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // ResizableMDIFrame.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 "ResizableMDIFrame.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CResizableMDIFrame
  25. IMPLEMENT_DYNCREATE(CResizableMDIFrame, CMDIFrameWnd)
  26. CResizableMDIFrame::CResizableMDIFrame()
  27. {
  28. m_bEnableSaveRestore = FALSE;
  29. }
  30. CResizableMDIFrame::~CResizableMDIFrame()
  31. {
  32. }
  33. BEGIN_MESSAGE_MAP(CResizableMDIFrame, CMDIFrameWnd)
  34. //{{AFX_MSG_MAP(CResizableMDIFrame)
  35. ON_WM_GETMINMAXINFO()
  36. ON_WM_DESTROY()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CResizableMDIFrame message handlers
  41. void CResizableMDIFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  42. {
  43. MinMaxInfo(lpMMI);
  44. BOOL bMaximized = FALSE;
  45. CMDIChildWnd* pChild = MDIGetActive(&bMaximized);
  46. if (pChild == NULL || !bMaximized)
  47. return;
  48. // get the extra size from child to frame
  49. CRect rectChild, rectWnd;
  50. GetWindowRect(rectWnd);
  51. RepositionBars(0, 0xFFFF, AFX_IDW_PANE_FIRST, reposQuery, rectChild);
  52. CSize sizeExtra = rectWnd.Size() - rectChild.Size();
  53. // ask the child frame for track size
  54. MINMAXINFO mmiView = *lpMMI;
  55. pChild->SendMessage(WM_GETMINMAXINFO, 0, (LPARAM)&mmiView);
  56. mmiView.ptMaxTrackSize = sizeExtra + mmiView.ptMaxTrackSize;
  57. mmiView.ptMinTrackSize = sizeExtra + mmiView.ptMinTrackSize;
  58. // min size is the largest
  59. lpMMI->ptMinTrackSize.x = __max(lpMMI->ptMinTrackSize.x,
  60. mmiView.ptMinTrackSize.x);
  61. lpMMI->ptMinTrackSize.y = __max(lpMMI->ptMinTrackSize.y,
  62. mmiView.ptMinTrackSize.y);
  63. // max size is the shortest
  64. lpMMI->ptMaxTrackSize.x = __min(lpMMI->ptMaxTrackSize.x,
  65. mmiView.ptMaxTrackSize.x);
  66. lpMMI->ptMaxTrackSize.y = __min(lpMMI->ptMaxTrackSize.y,
  67. mmiView.ptMaxTrackSize.y);
  68. // MDI should call default implementation
  69. CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
  70. }
  71. // NOTE: this must be called after setting the layout
  72. // to have the view and its controls displayed properly
  73. BOOL CResizableMDIFrame::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
  74. {
  75. m_sSection = pszSection;
  76. m_bEnableSaveRestore = TRUE;
  77. m_bRectOnly = bRectOnly;
  78. // restore immediately
  79. return LoadWindowRect(pszSection, bRectOnly);
  80. }
  81. void CResizableMDIFrame::OnDestroy()
  82. {
  83. if (m_bEnableSaveRestore)
  84. SaveWindowRect(m_sSection, m_bRectOnly);
  85. CMDIFrameWnd::OnDestroy();
  86. }