ResizablePageEx.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // ResizablePageEx.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 "ResizablePageEx.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CResizablePageEx
  26. IMPLEMENT_DYNCREATE(CResizablePageEx, CPropertyPageEx)
  27. CResizablePageEx::CResizablePageEx()
  28. {
  29. }
  30. CResizablePageEx::CResizablePageEx(UINT nIDTemplate, UINT nIDCaption, UINT nIDHeaderTitle, UINT nIDHeaderSubTitle)
  31. : CPropertyPageEx(nIDTemplate, nIDCaption, nIDHeaderTitle, nIDHeaderSubTitle)
  32. {
  33. }
  34. CResizablePageEx::CResizablePageEx(LPCTSTR lpszTemplateName, UINT nIDCaption, UINT nIDHeaderTitle, UINT nIDHeaderSubTitle)
  35. : CPropertyPageEx(lpszTemplateName, nIDCaption, nIDHeaderTitle, nIDHeaderSubTitle)
  36. {
  37. }
  38. CResizablePageEx::~CResizablePageEx()
  39. {
  40. }
  41. BEGIN_MESSAGE_MAP(CResizablePageEx, CPropertyPageEx)
  42. //{{AFX_MSG_MAP(CResizablePageEx)
  43. ON_WM_SIZE()
  44. ON_WM_ERASEBKGND()
  45. ON_WM_GETMINMAXINFO()
  46. ON_WM_DESTROY()
  47. ON_WM_CTLCOLOR()
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CResizablePageEx message handlers
  52. void CResizablePageEx::OnSize(UINT nType, int cx, int cy)
  53. {
  54. CWnd::OnSize(nType, cx, cy);
  55. ArrangeLayout();
  56. if (m_psp.dwFlags & PSP_HIDEHEADER)
  57. Invalidate();
  58. }
  59. BOOL CResizablePageEx::OnEraseBkgnd(CDC* pDC)
  60. {
  61. ClipChildren(pDC, FALSE);
  62. BOOL bRet = CPropertyPageEx::OnEraseBkgnd(pDC);
  63. ClipChildren(pDC, TRUE);
  64. return bRet;
  65. }
  66. void CResizablePageEx::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  67. {
  68. MinMaxInfo(lpMMI);
  69. }
  70. BOOL CResizablePageEx::OnInitDialog()
  71. {
  72. CPropertyPageEx::OnInitDialog();
  73. // set the initial size as the min track size
  74. CRect rc;
  75. GetWindowRect(&rc);
  76. SetMinTrackSize(rc.Size());
  77. // HACK: temporarily abandon subclassing
  78. // CAUSE: system subclasses this window after this message
  79. // ISSUE: our WindowProc is not the first to be called
  80. // and we miss some painting related messages
  81. if (Attach(UnsubclassWindow()))
  82. {
  83. CWnd* pParent = GetParent();
  84. pParent->LockWindowUpdate();
  85. Post_SheetPageExHack(pParent->GetSafeHwnd(), m_hWnd);
  86. }
  87. return TRUE; // return TRUE unless you set the focus to a control
  88. // EXCEPTION: OCX Property Pages should return FALSE
  89. }
  90. void CResizablePageEx::OnDestroy()
  91. {
  92. // remove child windows
  93. RemoveAllAnchors();
  94. ResetAllRects();
  95. CPropertyPageEx::OnDestroy();
  96. }
  97. HBRUSH CResizablePageEx::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  98. {
  99. // NOTE: this message couldn't be catched without the above hack
  100. HBRUSH hbr = CPropertyPageEx::OnCtlColor(pDC, pWnd, nCtlColor);
  101. if (hbr && (m_psp.dwFlags & PSP_HIDEHEADER))
  102. {
  103. // reposition origin of background brush
  104. // used for transparent effect on page controls
  105. // (needed with double-buffering and XP themes)
  106. CRect rect;
  107. pWnd->GetWindowRect(rect);
  108. pWnd->SendMessage(WM_NCCALCSIZE, FALSE, (LPARAM)&rect);
  109. ScreenToClient(rect);
  110. CPoint pt(-rect.TopLeft());
  111. HDC hDC = pDC->GetSafeHdc();
  112. ::LPtoDP(hDC, &pt, 1);
  113. ::UnrealizeObject(hbr);
  114. ::SetBrushOrgEx(hDC, pt.x, pt.y, NULL);
  115. }
  116. return hbr;
  117. }
  118. LRESULT CResizablePageEx::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  119. {
  120. if (message != WM_NCCALCSIZE || wParam == 0)
  121. return CPropertyPageEx::WindowProc(message, wParam, lParam);
  122. LRESULT lResult = 0;
  123. HandleNcCalcSize(FALSE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
  124. lResult = CPropertyPageEx::WindowProc(message, wParam, lParam);
  125. HandleNcCalcSize(TRUE, (LPNCCALCSIZE_PARAMS)lParam, lResult);
  126. return lResult;
  127. }