Operator Console
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ResizeDlg Class Reference

A class that resizes and centers dialog objects within a parent window. More...

#include <ResizeDlg.h>

Public Member Functions

 ResizeDlg (void)
 
virtual ~ResizeDlg (void)
 
void GetImageWindowDelta (int width, int height)
 Calculates the differences in window height and width between the current and new sizes. More...
 
void OffsetWindowSize (CWnd *wnd, int dx, int dy)
 Changes the window size. More...
 
void OffsetWindowPos (CWnd *parent, CWnd *wnd, int dx, int dy)
 Changes the window position. More...
 
void Resize (CWnd *dialog, CWnd *window, int width, int height)
 Resizes an object within a parent window but does not allow the object to shrink vertically. More...
 
void BidirectionalResize (CWnd *dialog, CWnd *window, int width, int height)
 Resizes an object within a parent window that allows the object to shrink vertically, but not below a minimum size. More...
 
 ResizeDlg (void)
 
virtual ~ResizeDlg (void)
 
void GetImageWindowDelta (int width, int height)
 
void OffsetWindowSize (CWnd *wnd, int dx, int dy)
 
void OffsetWindowPos (CWnd *parent, CWnd *wnd, int dx, int dy)
 
void Resize (CWnd *dialog, CWnd *window, int width, int height)
 
void BidirectionalResize (CWnd *dialog, CWnd *window, int width, int height)
 

Static Public Member Functions

static void CenterWindow (CWnd *parent, CWnd *wnd, bool horizontal=true, bool vertical=true)
 A function that centers an object with respect to the parent with the option to select only vertical or horizontal centering. More...
 
static void GetWindowCenter (CWnd *wnd, CRect *bnds, CPoint *center)
 
static void GetWindowSize (CWnd *wnd, int *width, int *height, CRect *bnds=NULL, bool client=false)
 A function that acquires either the window or client size. More...
 
static BOOL CALLBACK OffsetChildPos (HWND hwnd, LPARAM lParam)
 
static void CenterWindow (CWnd *parent, CWnd *wnd, bool horizontal=true, bool vertical=true)
 
static void GetWindowCenter (CWnd *wnd, CRect *bnds, CPoint *center)
 
static void GetWindowSize (CWnd *wnd, int *width, int *height, CRect *bnds=NULL, bool client=false)
 
static BOOL CALLBACK OffsetChildPos (HWND hwnd, LPARAM lParam)
 

Protected Attributes

CSize m_delta
 
CWnd * m_dialog
 
CWnd * m_window
 

Detailed Description

A class that resizes and centers dialog objects within a parent window.

Constructor & Destructor Documentation

ResizeDlg::ResizeDlg ( void  )
33 {
34 }
ResizeDlg::~ResizeDlg ( void  )
virtual
38 {
39 }
ResizeDlg::ResizeDlg ( void  )
virtual ResizeDlg::~ResizeDlg ( void  )
virtual

Member Function Documentation

void ResizeDlg::BidirectionalResize ( CWnd *  dialog,
CWnd *  window,
int  width,
int  height 
)

Resizes an object within a parent window that allows the object to shrink vertically, but not below a minimum size.

Parameters
*dialogpointer to the parent window
*windowpointer to the object to be resized
widththe new width in pixels
heightthe new height in pixels

References CenterWindow(), MoveData::delta, MoveData::dialog, GetImageWindowDelta(), GetWindowSize(), m_delta, m_dialog, m_window, OffsetChildPos(), OffsetWindowSize(), and MoveData::skip.

Referenced by COperatorConsoleDlg::ReInitDialog().

316 {
317  MoveData data;
318  int dy;
319  int clientWidth, clientHeight;
320  int screenWidth, screenHeight;
321  m_dialog = dialog;
322  m_window = window;
323  GetWindowSize(dialog, &clientWidth, &clientHeight,NULL,true);
324  GetWindowSize(dialog, &screenWidth, &screenHeight);
325  //
326  // Get the difference in size between the window an the desired width and height
327  //
329 
330  if (m_delta.cx != 0 || m_delta.cy != 0)
331  {
332  //
333  // Resize the window
334  //
335  OffsetWindowSize(window, m_delta.cx, m_delta.cy);
336 
337  if (m_delta.cx < -16)
338  m_delta.cx += 16;
339 
340  //
341  // Resize the dialog. It can grow or shrink in x uncontrolled, but
342  // its height may not be less than a minimum value. Also, if we need to
343  // resize, it shouldn't make the window needlessly large.
344  //
345  int border = 16;
346  int min_window_size = 660;
347  if ( m_delta.cy >= 0) // only change size if needed
348  {
349  if (clientHeight < height)
350  {
351  dy = height - clientHeight+border;
352  }
353  else
354  {
355  dy = 0;
356  }
357 
358  }
359  else if ( clientHeight + m_delta.cy> min_window_size) // allow window to shrink if it won't go below minimum size
360  {
361  dy = m_delta.cy;
362  }
363  else
364  {
365  dy = min_window_size - screenHeight+(screenHeight - clientHeight); // shrink size to minimum size + width of the
366  } // screen border (screenHeight - clientHeight)
367  OffsetWindowSize(dialog, m_delta.cx, dy);
368  //
369  // Center the window vertically in the dialog
370  //
371  CenterWindow(dialog, window, false, true);
372 
373  //
374  // Move the rest of the items dx pixels to the left or right. We're not
375  // going to change the y coordinates, so we set m_delta.cy to 0.
376  //
377  m_delta.cy = 0;
378 
379  //
380  // Move all of the dialog items to compensate for the new size of 'window'. EnumChildWindows()
381  // will call OffsetChildPos() for each of the Dialog's child windows (i.e. all dialog items).
382  // We want to move every item except for the image item.
383  //
384  data.delta = &m_delta;
385  data.skip = window->m_hWnd; // we don't want to move 'window'
386  data.dialog = dialog->m_hWnd; // handle to the dialog window (we need this for converting coordinates)
387  ::EnumChildWindows(dialog->m_hWnd, OffsetChildPos, (LPARAM)&data);
388  }
389 }
CWnd * m_dialog
Definition: ResizeDlg.h:41
void GetImageWindowDelta(int width, int height)
Calculates the differences in window height and width between the current and new sizes...
Definition: ResizeDlg.cpp:104
CSize * delta
points to a CSize that details how much to shift the window horizontally and vertically ...
Definition: ResizeDlg.cpp:27
static void CenterWindow(CWnd *parent, CWnd *wnd, bool horizontal=true, bool vertical=true)
A function that centers an object with respect to the parent with the option to select only vertical ...
Definition: ResizeDlg.cpp:254
CSize m_delta
Definition: ResizeDlg.h:40
static void GetWindowSize(CWnd *wnd, int *width, int *height, CRect *bnds=NULL, bool client=false)
A function that acquires either the window or client size.
Definition: ResizeDlg.cpp:199
CWnd * m_window
Definition: ResizeDlg.h:42
A struct for containing data relevant for moving a window.
Definition: ResizeDlg.cpp:25
void OffsetWindowSize(CWnd *wnd, int dx, int dy)
Changes the window size.
Definition: ResizeDlg.cpp:126
HWND dialog
pointer to the dialog that needs to be moved
Definition: ResizeDlg.cpp:29
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2
HWND skip
pointer to the window that should not be moved i.e. the main window during a resize event ...
Definition: ResizeDlg.cpp:28
static BOOL CALLBACK OffsetChildPos(HWND hwnd, LPARAM lParam)
Definition: ResizeDlg.cpp:150

Here is the call graph for this function:

Here is the caller graph for this function:

void ResizeDlg::BidirectionalResize ( CWnd *  dialog,
CWnd *  window,
int  width,
int  height 
)
void ResizeDlg::CenterWindow ( CWnd *  parent,
CWnd *  wnd,
bool  horizontal = true,
bool  vertical = true 
)
static

A function that centers an object with respect to the parent with the option to select only vertical or horizontal centering.

Parameters
*parentpointer to the parent window
*wndpointer to the object to be centered
horizontalset to TRUE if horizontal centering is desired
verticalset to TRUE if vertical centering is desired

Referenced by BidirectionalResize(), and Resize().

255 {
256  if (wnd != NULL)
257  {
258  CRect r, rect, client;
259  CPoint ul;
260  int width, height, w, h;
261 
262  //
263  // Get the width, height, and screen coordinates of the windows
264  //
265  GetWindowSize(parent, &w, &h, &r, true); // r = client rect of parent
266  GetWindowSize(wnd, &width, &height, &rect,false); // rect is in screen coordinates
267 
268  //
269  // Convert the upper left coordinate of wnd to local coordinates (relative to parent)
270  //
271  ul.x = rect.left;
272  ul.y = rect.top;
273  parent->ScreenToClient(&ul);
274 
275  if (horizontal)
276  {
277  ul.x = (w - width) / 2; // local coordinate
278  }
279 
280  if (vertical)
281  {
282  ul.y = (h - height) / 2; // local coordinate
283  }
284 
285  //
286  // For some reason the x and y coordinates are off by a factor of 2, so I'm adjusting here.
287  // I don't know why that is, but I did a screen capture and measured the window positions
288  // in a paint program, and they were twice as much as they should have been.
289  //
290 
291  if (horizontal)
292  {
293  ul.x /= 2;
294  }
295 
296  if (vertical)
297  {
298  ul.y /= 2;
299  }
300 
301  wnd->MoveWindow(ul.x, ul.y, width, height,true);
302  //wnd->SetWindowPos(NULL, ul.x, ul.y, width, height, SWP_NOSIZE|SWP_NOZORDER);
303 
304  }
305 }
w
Definition: calculation_checks.m:5
static void GetWindowSize(CWnd *wnd, int *width, int *height, CRect *bnds=NULL, bool client=false)
A function that acquires either the window or client size.
Definition: ResizeDlg.cpp:199
h
Definition: calculation_checks.m:6
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2

Here is the caller graph for this function:

static void ResizeDlg::CenterWindow ( CWnd *  parent,
CWnd *  wnd,
bool  horizontal = true,
bool  vertical = true 
)
static
void ResizeDlg::GetImageWindowDelta ( int  width,
int  height 
)

Calculates the differences in window height and width between the current and new sizes.

References GetWindowSize(), m_delta, and m_window.

Referenced by BidirectionalResize(), and Resize().

105 {
106  int itemWidth, itemHeight;
107 
108 
109  //
110  // Get the current width and height of the image dialog item
111  //
112  GetWindowSize(m_window, &itemWidth, &itemHeight);
113 
114  //
115  // Get the difference in the width and height.
116  // This is how much the sizes of the image item and dialog need to be increased.
117  // This is also how much we need to move the other dialog items to accommodate the new image size.
118  //
119  m_delta.cx = width - itemWidth;
120  m_delta.cy = height - itemHeight;
121 }
CSize m_delta
Definition: ResizeDlg.h:40
static void GetWindowSize(CWnd *wnd, int *width, int *height, CRect *bnds=NULL, bool client=false)
A function that acquires either the window or client size.
Definition: ResizeDlg.cpp:199
CWnd * m_window
Definition: ResizeDlg.h:42
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2

Here is the call graph for this function:

Here is the caller graph for this function:

void ResizeDlg::GetImageWindowDelta ( int  width,
int  height 
)
void ResizeDlg::GetWindowCenter ( CWnd *  wnd,
CRect *  bnds,
CPoint *  center 
)
static
178 {
179  if (wnd != NULL && center != NULL)
180  {
181  CRect rect;
182  CRect *r = (bnds != NULL) ? bnds : &rect;
183 
184  wnd->GetWindowRect(r);
185  *center = r->CenterPoint();
186  }
187 }
static void ResizeDlg::GetWindowCenter ( CWnd *  wnd,
CRect *  bnds,
CPoint *  center 
)
static
void ResizeDlg::GetWindowSize ( CWnd *  wnd,
int *  width,
int *  height,
CRect *  bnds = NULL,
bool  client = false 
)
static

A function that acquires either the window or client size.

Note that the client size does not include the window border, whereas the window size does.

Parameters
*wndthe window
*widthpointer to an int into which the width is stored
*heightpointer to an int into which the height is stored
*bnds[OPTIONAL] a CRect to store the window dimensions; supply NULL if not desired
clientSupply TRUE if the client size is desired, FALSE if the window size is desired

Referenced by BidirectionalResize(), GetImageWindowDelta(), OffsetWindowSize(), and COperatorConsoleDlg::QsoMove().

200 {
201  if (wnd != NULL)
202  {
203  CRect rect;
204 
205  CRect *r = (bnds == NULL) ? &rect : bnds;
206 
207  if (client)
208  {
209  wnd->GetClientRect(r);
210  }
211  else
212  {
213  wnd->GetWindowRect(r);
214  }
215 
216  if (width != NULL)
217  {
218  *width = r->Width();
219  }
220 
221  if (height != NULL)
222  {
223  *height = r->Height();
224  }
225  }
226 }
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2

Here is the caller graph for this function:

static void ResizeDlg::GetWindowSize ( CWnd *  wnd,
int *  width,
int *  height,
CRect *  bnds = NULL,
bool  client = false 
)
static
static BOOL CALLBACK ResizeDlg::OffsetChildPos ( HWND  hwnd,
LPARAM  lParam 
)
static
BOOL CALLBACK ResizeDlg::OffsetChildPos ( HWND  hwnd,
LPARAM  lParam 
)
static

References MoveData::delta, MoveData::dialog, height, MoveData::skip, and width.

Referenced by BidirectionalResize(), and Resize().

151 {
152  MoveData *data = (MoveData *)lParam;
153  RECT rect;
154  int width, height;
155  POINT ul;
156 
157  if (hwnd != data->skip)
158  {
159  ::GetWindowRect(hwnd, &rect); // rect is in screen coordinates
160 
161  ul.x = rect.left;
162  ul.y = rect.top;
163  ::ScreenToClient(data->dialog, &ul); // make ul coordinates relative to dialog
164 
165  width = rect.right - rect.left;
166  height = rect.bottom - rect.top;
167 
168  ::MoveWindow(hwnd, ul.x + data->delta->cx, ul.y + data->delta->cy, width, height, TRUE);
169  }
170 
171  return TRUE;
172 }
CSize * delta
points to a CSize that details how much to shift the window horizontally and vertically ...
Definition: ResizeDlg.cpp:27
A struct for containing data relevant for moving a window.
Definition: ResizeDlg.cpp:25
HWND dialog
pointer to the dialog that needs to be moved
Definition: ResizeDlg.cpp:29
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2
HWND skip
pointer to the window that should not be moved i.e. the main window during a resize event ...
Definition: ResizeDlg.cpp:28

Here is the caller graph for this function:

void ResizeDlg::OffsetWindowPos ( CWnd *  parent,
CWnd *  wnd,
int  dx,
int  dy 
)
void ResizeDlg::OffsetWindowPos ( CWnd *  parent,
CWnd *  wnd,
int  dx,
int  dy 
)

Changes the window position.

138 {
139  if (wnd != NULL)
140  {
141  CRect rect;
142  wnd->GetWindowRect(&rect); // current window location in screen coordinates
143  parent->ScreenToClient(&rect); // current location in client coordinates (relative to client rect of parent)
144  rect.OffsetRect(dx, dy); // offset the rect by (dx, dy)
145  wnd->MoveWindow(&rect, TRUE); // move the window
146  }
147 }
void ResizeDlg::OffsetWindowSize ( CWnd *  wnd,
int  dx,
int  dy 
)

Changes the window size.

References GetWindowSize(), height, and width.

Referenced by BidirectionalResize(), and Resize().

127 {
128  int width, height;
129 
130  GetWindowSize(wnd, &width, &height);
131  wnd->SetWindowPos(NULL, 0, 0, width + dx, height + dy, SWP_NOMOVE | SWP_NOZORDER);
132 }
static void GetWindowSize(CWnd *wnd, int *width, int *height, CRect *bnds=NULL, bool client=false)
A function that acquires either the window or client size.
Definition: ResizeDlg.cpp:199
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2

Here is the call graph for this function:

Here is the caller graph for this function:

void ResizeDlg::OffsetWindowSize ( CWnd *  wnd,
int  dx,
int  dy 
)
void ResizeDlg::Resize ( CWnd *  dialog,
CWnd *  window,
int  width,
int  height 
)
void ResizeDlg::Resize ( CWnd *  dialog,
CWnd *  window,
int  width,
int  height 
)

Resizes an object within a parent window but does not allow the object to shrink vertically.

Parameters
dialogpointer to the parent window
windowpointer to the object to be resized
widththe new width in pixels
heightthe new height in pixels

References CenterWindow(), MoveData::delta, MoveData::dialog, GetImageWindowDelta(), m_delta, m_dialog, m_window, OffsetChildPos(), OffsetWindowSize(), and MoveData::skip.

Referenced by COperatorConsoleDlg::OnInitDialog().

49 {
50  MoveData data;
51  int dy;
52 
53  m_dialog = dialog;
54  m_window = window;
55 
56  //
57  // Get the difference in size between the window and the desired width and height
58  //
60 
61  if (m_delta.cx != 0 || m_delta.cy != 0)
62  {
63  //
64  // Resize the window
65  //
66  OffsetWindowSize(window, m_delta.cx, m_delta.cy);
67 
68  if (m_delta.cx < -16)
69  m_delta.cx += 16;
70 
71  //
72  // Resize the dialog. It can grow or shrink in x, but
73  // its height may not be less than its original height.
74  //
75  dy = m_delta.cy > 0 ? m_delta.cy : 0;
76  OffsetWindowSize(dialog, m_delta.cx, dy); // resize the dialog
77 
78  //
79  // Center the window vertically in the dialog
80  //
81  CenterWindow(dialog, window, false, true);
82 
83  //
84  // Move the rest of the items dx pixels to the left or right. We're not
85  // going to change the y coordinates, so we set m_delta.cy to 0.
86  //
87  m_delta.cy = 0;
88 
89  //
90  // Move all of the dialog items to compensate for the new size of 'window'. EnumChildWindows()
91  // will call OffsetChildPos() for each of the Dialog's child windows (i.e. all dialog items).
92  // We want to move every item except for the image item.
93  //
94  data.delta = &m_delta;
95  data.skip = window->m_hWnd; // we don't want to move 'window'
96  data.dialog = dialog->m_hWnd; // handle to the dialog window (we need this for converting coordinates)
97  ::EnumChildWindows(dialog->m_hWnd, OffsetChildPos, (LPARAM)&data);
98  }
99 }
CWnd * m_dialog
Definition: ResizeDlg.h:41
void GetImageWindowDelta(int width, int height)
Calculates the differences in window height and width between the current and new sizes...
Definition: ResizeDlg.cpp:104
CSize * delta
points to a CSize that details how much to shift the window horizontally and vertically ...
Definition: ResizeDlg.cpp:27
static void CenterWindow(CWnd *parent, CWnd *wnd, bool horizontal=true, bool vertical=true)
A function that centers an object with respect to the parent with the option to select only vertical ...
Definition: ResizeDlg.cpp:254
CSize m_delta
Definition: ResizeDlg.h:40
CWnd * m_window
Definition: ResizeDlg.h:42
A struct for containing data relevant for moving a window.
Definition: ResizeDlg.cpp:25
void OffsetWindowSize(CWnd *wnd, int dx, int dy)
Changes the window size.
Definition: ResizeDlg.cpp:126
HWND dialog
pointer to the dialog that needs to be moved
Definition: ResizeDlg.cpp:29
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2
HWND skip
pointer to the window that should not be moved i.e. the main window during a resize event ...
Definition: ResizeDlg.cpp:28
static BOOL CALLBACK OffsetChildPos(HWND hwnd, LPARAM lParam)
Definition: ResizeDlg.cpp:150

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

CSize ResizeDlg::m_delta
protected
CWnd * ResizeDlg::m_dialog
protected

Referenced by BidirectionalResize(), and Resize().

CWnd * ResizeDlg::m_window
protected

The documentation for this class was generated from the following files: