ResizableMDIChild.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // ResizableMDIChild.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 "ResizableMDIChild.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CResizableMDIChild
  26. IMPLEMENT_DYNCREATE(CResizableMDIChild, CMDIChildWnd)
  27. CResizableMDIChild::CResizableMDIChild()
  28. {
  29. m_bEnableSaveRestore = FALSE;
  30. m_bRectOnly = FALSE;
  31. }
  32. CResizableMDIChild::~CResizableMDIChild()
  33. {
  34. }
  35. BEGIN_MESSAGE_MAP(CResizableMDIChild, CMDIChildWnd)
  36. //{{AFX_MSG_MAP(CResizableMDIChild)
  37. ON_WM_GETMINMAXINFO()
  38. ON_WM_SIZE()
  39. ON_WM_DESTROY()
  40. ON_WM_NCCREATE()
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CResizableMDIChild message handlers
  45. void CResizableMDIChild::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  46. {
  47. // MDI should call default implementation
  48. CMDIChildWnd::OnGetMinMaxInfo(lpMMI);
  49. MinMaxInfo(lpMMI);
  50. CWnd* pView = GetDlgItem(AFX_IDW_PANE_FIRST);//GetActiveView();
  51. if (pView != NULL)
  52. ChainMinMaxInfo(lpMMI, this, pView);
  53. }
  54. void CResizableMDIChild::OnSize(UINT nType, int cx, int cy)
  55. {
  56. CMDIChildWnd::OnSize(nType, cx, cy);
  57. /* Why was this necessary???
  58. // make sure the MDI parent frame doesn't clip
  59. // this child window when it is maximized
  60. if (nType == SIZE_MAXIMIZED)
  61. {
  62. CMDIFrameWnd* pFrame = GetMDIFrame();
  63. CRect rect;
  64. pFrame->GetWindowRect(rect);
  65. pFrame->MoveWindow(rect);
  66. }
  67. /*/
  68. }
  69. // NOTE: this must be called after setting the layout
  70. // to have the view and its controls displayed properly
  71. BOOL CResizableMDIChild::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
  72. {
  73. m_sSection = pszSection;
  74. m_bEnableSaveRestore = TRUE;
  75. m_bRectOnly = bRectOnly;
  76. // restore immediately
  77. return LoadWindowRect(pszSection, bRectOnly);
  78. }
  79. void CResizableMDIChild::OnDestroy()
  80. {
  81. if (m_bEnableSaveRestore)
  82. SaveWindowRect(m_sSection, m_bRectOnly);
  83. // reset instance data
  84. RemoveAllAnchors();
  85. ResetAllRects();
  86. m_bEnableSaveRestore = FALSE;
  87. CMDIChildWnd::OnDestroy();
  88. }
  89. LRESULT CResizableMDIChild::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  90. {
  91. if (message != WM_NCCALCSIZE || wParam == 0)
  92. return CMDIChildWnd::WindowProc(message, wParam, lParam);
  93. // specifying valid rects needs controls already anchored
  94. LRESULT lResult = 0;
  95. HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
  96. lResult = CMDIChildWnd::WindowProc(message, wParam, lParam);
  97. HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
  98. return lResult;
  99. }
  100. BOOL CResizableMDIChild::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
  101. {
  102. if (!CMDIChildWnd::OnNcCreate(lpCreateStruct))
  103. return FALSE;
  104. ModifyStyle(0, WS_CLIPCHILDREN);
  105. return TRUE;
  106. }