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