ResizableMDIChild.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // ResizableMDIChild.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 "ResizableMDIChild.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CResizableMDIChild
  25. IMPLEMENT_DYNCREATE(CResizableMDIChild, CMDIChildWnd)
  26. CResizableMDIChild::CResizableMDIChild()
  27. {
  28. m_bEnableSaveRestore = FALSE;
  29. }
  30. CResizableMDIChild::~CResizableMDIChild()
  31. {
  32. }
  33. BEGIN_MESSAGE_MAP(CResizableMDIChild, CMDIChildWnd)
  34. //{{AFX_MSG_MAP(CResizableMDIChild)
  35. ON_WM_GETMINMAXINFO()
  36. ON_WM_SIZE()
  37. ON_WM_DESTROY()
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CResizableMDIChild message handlers
  42. void CResizableMDIChild::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  43. {
  44. MinMaxInfo(lpMMI);
  45. CView* pView = GetActiveView();
  46. if (pView == NULL)
  47. return;
  48. // get the extra size from view to frame
  49. CRect rectClient, rectWnd;
  50. if (IsZoomed())
  51. GetClientRect(rectWnd);
  52. else
  53. GetWindowRect(rectWnd);
  54. RepositionBars(0, 0xFFFF, AFX_IDW_PANE_FIRST, reposQuery, rectClient);
  55. CSize sizeExtra = rectWnd.Size() - rectClient.Size();
  56. // ask the view for track size
  57. MINMAXINFO mmiView = *lpMMI;
  58. pView->SendMessage(WM_GETMINMAXINFO, 0, (LPARAM)&mmiView);
  59. mmiView.ptMaxTrackSize = sizeExtra + mmiView.ptMaxTrackSize;
  60. mmiView.ptMinTrackSize = sizeExtra + mmiView.ptMinTrackSize;
  61. // min size is the largest
  62. lpMMI->ptMinTrackSize.x = __max(lpMMI->ptMinTrackSize.x,
  63. mmiView.ptMinTrackSize.x);
  64. lpMMI->ptMinTrackSize.y = __max(lpMMI->ptMinTrackSize.y,
  65. mmiView.ptMinTrackSize.y);
  66. // max size is the shortest
  67. lpMMI->ptMaxTrackSize.x = __min(lpMMI->ptMaxTrackSize.x,
  68. mmiView.ptMaxTrackSize.x);
  69. lpMMI->ptMaxTrackSize.y = __min(lpMMI->ptMaxTrackSize.y,
  70. mmiView.ptMaxTrackSize.y);
  71. // MDI should call default implementation
  72. CMDIChildWnd::OnGetMinMaxInfo(lpMMI);
  73. }
  74. void CResizableMDIChild::OnSize(UINT nType, int cx, int cy)
  75. {
  76. CMDIChildWnd::OnSize(nType, cx, cy);
  77. // make sure the MDI parent frame doesn't clip
  78. // this child window when it is maximized
  79. if (nType == SIZE_MAXIMIZED)
  80. {
  81. CMDIFrameWnd* pFrame = GetMDIFrame();
  82. CRect rect;
  83. pFrame->GetWindowRect(rect);
  84. pFrame->MoveWindow(rect);
  85. }
  86. }
  87. // NOTE: this must be called after setting the layout
  88. // to have the view and its controls displayed properly
  89. BOOL CResizableMDIChild::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
  90. {
  91. m_sSection = pszSection;
  92. m_bEnableSaveRestore = TRUE;
  93. m_bRectOnly = bRectOnly;
  94. // restore immediately
  95. return LoadWindowRect(pszSection, bRectOnly);
  96. }
  97. void CResizableMDIChild::OnDestroy()
  98. {
  99. if (m_bEnableSaveRestore)
  100. SaveWindowRect(m_sSection, m_bRectOnly);
  101. CMDIChildWnd::OnDestroy();
  102. }