DialogResizer.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // DialogResizer.cpp: implementation of the CDialogResizer class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "DialogResizer.h"
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char THIS_FILE[]=__FILE__;
  9. #define new DEBUG_NEW
  10. #endif
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. CDialogResizer::CDialogResizer()
  15. {
  16. }
  17. CDialogResizer::~CDialogResizer()
  18. {
  19. }
  20. void CDialogResizer::SetParent(HWND hWndParent)
  21. {
  22. m_hWndParent = hWndParent;
  23. CRect cr;
  24. GetClientRect(m_hWndParent, cr);
  25. m_DlgSize.cx = cr.Width();
  26. m_DlgSize.cy = cr.Height();
  27. }
  28. void CDialogResizer::AddControl(int nControlID, int nFlags)
  29. {
  30. HWND hWnd = GetDlgItem(m_hWndParent, nControlID);
  31. if(hWnd)
  32. AddControl(hWnd, nFlags);
  33. }
  34. void CDialogResizer::AddControl(HWND hWnd, int nFlags)
  35. {
  36. CDR_Data data;
  37. data.m_hWnd = hWnd;
  38. data.m_nFlags = nFlags;
  39. m_Controls.Add(data);
  40. }
  41. void CDialogResizer::MoveControls(CSize csNewSize)
  42. {
  43. int nDeltaX = csNewSize.cx - m_DlgSize.cx;
  44. int nDeltaY = csNewSize.cy - m_DlgSize.cy;
  45. if(nDeltaX == 0 && nDeltaY == 0)
  46. return;
  47. m_DlgSize = csNewSize;
  48. INT_PTR nCount = m_Controls.GetSize();
  49. CRect rc;
  50. CRect rcParent;
  51. GetClientRect(m_hWndParent, rcParent);
  52. for(int i = 0; i < nCount; i++)
  53. {
  54. CDR_Data data = m_Controls[i];
  55. GetWindowRect(data.m_hWnd, rc);
  56. MapWindowPoints(GetDesktopWindow(), m_hWndParent, (LPPOINT)&rc, 2 );
  57. //
  58. // Adjust the window horizontally
  59. if( data.m_nFlags & DR_MoveLeft )
  60. {
  61. rc.left += nDeltaX;
  62. rc.right += nDeltaX;
  63. }
  64. //
  65. // Adjust the window vertically
  66. if( data.m_nFlags & DR_MoveTop )
  67. {
  68. rc.top += nDeltaY;
  69. rc.bottom += nDeltaY;
  70. }
  71. //
  72. // Size the window horizontally
  73. if( data.m_nFlags & DR_SizeWidth )
  74. {
  75. rc.right += nDeltaX;
  76. }
  77. // Size the window vertically
  78. if( data.m_nFlags & DR_SizeHeight )
  79. {
  80. rc.bottom += nDeltaY;
  81. }
  82. ::SetWindowPos(data.m_hWnd, NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
  83. }
  84. ::RedrawWindow(m_hWndParent, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
  85. }