ResizableMDIFrame.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // ResizableMDIFrame.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 "ResizableMDIFrame.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CResizableMDIFrame
  26. IMPLEMENT_DYNCREATE(CResizableMDIFrame, CMDIFrameWnd)
  27. CResizableMDIFrame::CResizableMDIFrame()
  28. {
  29. m_bEnableSaveRestore = FALSE;
  30. m_bRectOnly = FALSE;
  31. }
  32. CResizableMDIFrame::~CResizableMDIFrame()
  33. {
  34. }
  35. BEGIN_MESSAGE_MAP(CResizableMDIFrame, CMDIFrameWnd)
  36. //{{AFX_MSG_MAP(CResizableMDIFrame)
  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. // CResizableMDIFrame message handlers
  45. void CResizableMDIFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  46. {
  47. // MDI should call default implementation
  48. CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
  49. MinMaxInfo(lpMMI);
  50. BOOL bMaximized = FALSE;
  51. CMDIChildWnd* pChild = MDIGetActive(&bMaximized);
  52. if (pChild != NULL && bMaximized)
  53. ChainMinMaxInfo(lpMMI, this, pChild);
  54. }
  55. // NOTE: this must be called after setting the layout
  56. // to have the view and its controls displayed properly
  57. BOOL CResizableMDIFrame::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
  58. {
  59. m_sSection = pszSection;
  60. m_bEnableSaveRestore = TRUE;
  61. m_bRectOnly = bRectOnly;
  62. // restore immediately
  63. return LoadWindowRect(pszSection, bRectOnly);
  64. }
  65. void CResizableMDIFrame::OnDestroy()
  66. {
  67. if (m_bEnableSaveRestore)
  68. SaveWindowRect(m_sSection, m_bRectOnly);
  69. // reset instance data
  70. RemoveAllAnchors();
  71. ResetAllRects();
  72. m_bEnableSaveRestore = FALSE;
  73. CMDIFrameWnd::OnDestroy();
  74. }
  75. BOOL CResizableMDIFrame::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
  76. {
  77. if (!CMDIFrameWnd::OnNcCreate(lpCreateStruct))
  78. return FALSE;
  79. MakeResizable(lpCreateStruct);
  80. return TRUE;
  81. }
  82. LRESULT CResizableMDIFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  83. {
  84. if (message != WM_NCCALCSIZE || wParam == 0)
  85. return CMDIFrameWnd::WindowProc(message, wParam, lParam);
  86. // specifying valid rects needs controls already anchored
  87. LRESULT lResult = 0;
  88. HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
  89. lResult = CMDIFrameWnd::WindowProc(message, wParam, lParam);
  90. HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
  91. return lResult;
  92. }
  93. void CResizableMDIFrame::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
  94. {
  95. CMDIFrameWnd::OnWindowPosChanging(lpwndpos);
  96. // since this window class doesn't have the style CS_HREDRAW|CS_VREDRAW
  97. // the client area is not invalidated during a resize operation and
  98. // this prevents the system from using WM_NCCALCSIZE to validate rects
  99. Invalidate();
  100. }