📄 orderer.cpp
字号:
#include "stdafx.h"
#include "orderer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma warning ( disable : 4711 )
/////////////////////////////////////////////////////////////////////////////
// COrderer
COrder::Set (DWORD nType, LPRECT lpRect, HWND hRel)
{
type = nType;
rc = lpRect;
wnd = hRel;
}
COrderer::COrderer () : m_pWnd (NULL)
{
}
COrderer:: ~ COrderer ()
{
RemoveAllChildren ();
}
void COrderer::
AddChild (HWND hWnd, DWORD nType, LPRECT lpRect, HWND hRel)
{
COrder order;
//#ifndef NDEBUG
// ASSERT (!m_lstWindows.Lookup (hWnd, order));
//#endif // NDEBUG
order.Set (nType, lpRect, hRel);
m_lstWindows.SetAt (hWnd, order);
ASSERT (m_pWnd);
CRect rc;
m_pWnd->GetClientRect (rc);
COrderer::OnSize (0, rc.Width (), rc.Height ());
}
void COrderer::
RemoveChild (HWND hWnd)
{
m_lstWindows.RemoveKey (hWnd);
}
void COrderer::
RemoveAllChildren ()
{
m_lstWindows.RemoveAll ();
}
#pragma warning ( disable : 4100 )
void COrderer::
OnSize (UINT nType, int cx, int cy)
{
if (!m_lstWindows.IsEmpty ())
{
POSITION p = m_lstWindows.GetStartPosition ();
HWND hWnd;
COrder order;
DWORD nMode;
CWnd *w;
bool rel;
CRect rrel;
ASSERT (p);
do
{
m_lstWindows.GetNextAssoc (p, hWnd, order);
if (::IsWindow (hWnd) && (w = CWnd::FromHandle (hWnd)) != NULL)
{
CRect rc;
if (order.type)
{
if (order.wnd &&::IsWindow (order.wnd))
{
rel = true;
CWnd::FromHandle (order.wnd)->GetWindowRect (rrel);
}
else
{
rel = false;
}
w->GetWindowRect (rc);
nMode = SWP_NOZORDER;
if (order.type & ORD_MOVE)
{
if (order.type & ORD_MOVE_X)
{
// !!! must be DeltaX
rc.left += cx;
rc.right += cx;
}
if (order.type & ORD_MOVE_Y)
{
// !!! must be DeltaY
rc.top += cy;
rc.bottom += cy;
}
}
else
{
nMode |= SWP_NOMOVE;
}
if (order.type & ORD_SIZE)
{
if (order.type & ORD_SIZE_X)
{
// !!! must be DeltaX
rc.right += cx;
}
if (order.type & ORD_SIZE_Y)
{
// !!! must be DeltaY
rc.bottom += cy;
}
}
else
{
nMode |= SWP_NOSIZE;
}
if (order.type & ORD_ZERO_BEGIN)
{
if (order.type & ORD_ZERO_LEFT)
{
rc.left = 0;
}
if (order.type & ORD_ZERO_TOP)
{
rc.top = 0;
}
nMode &= ~(SWP_NOMOVE | SWP_NOSIZE);
}
if (order.type & ORD_FULL_END)
{
if (order.type & ORD_FULL_RIGHT)
{
rc.right = cx + rc.left;
}
if (order.type & ORD_FULL_BOTTOM)
{
rc.bottom = cy + rc.top;
}
nMode &= ~SWP_NOSIZE;
}
if (order.type & ORD_SET_BEGIN)
{
if (order.type & ORD_SET_LEFT)
{
rc.left = rel ? rrel.left + order.rc.left : order.rc.left;
}
if (order.type & ORD_SET_TOP)
{
rc.top = rel ? rrel.top + order.rc.top : order.rc.top;
}
nMode &= ~(SWP_NOMOVE | SWP_NOSIZE);
}
if (order.type & ORD_SET_BACK_BEGIN)
{
if (order.type & ORD_SET_BACK_LEFT)
{
rc.left = rel ? rrel.right - order.rc.left : cx - order.rc.left;
}
if (order.type & ORD_SET_BACK_TOP)
{
rc.top = rel ? rrel.bottom - order.rc.top : cy - order.rc.top;
}
nMode &= ~(SWP_NOMOVE | SWP_NOSIZE);
}
if (order.type & ORD_SET_END)
{
if (order.type & ORD_SET_RIGHT)
{
rc.right = rel ? rrel.right + order.rc.right : order.rc.right;
}
if (order.type & ORD_SET_BOTTOM)
{
rc.bottom = rel ? rrel.bottom + order.rc.bottom : order.rc.bottom;
}
nMode &= ~SWP_NOSIZE;
}
if (order.type & ORD_SET_BACK_END)
{
if (order.type & ORD_SET_BACK_RIGHT)
{
rc.right = rel ? rrel.right - order.rc.right : cx - order.rc.right;
}
if (order.type & ORD_SET_BACK_BOTTOM)
{
rc.bottom = rel ? rrel.bottom - order.rc.bottom : cy - order.rc.bottom;
}
nMode &= ~SWP_NOSIZE;
}
if (order.type & ORD_SET_SIZE)
{
if (order.type & ORD_SET_WIDTH)
{
rc.right = rel ? rc.left + rrel.Width () + order.rc.Width () : rc.left + order.rc.Width ();
}
if (order.type & ORD_SET_HEIGHT)
{
rc.bottom = rel ? rc.top + rrel.Height () + order.rc.Height () : rc.top + order.rc.Height ();
}
nMode &= ~SWP_NOSIZE;
}
w->SetWindowPos (NULL, rc.left, rc.top, rc.Width (), rc.Height (), nMode);
}
}
}
while (p);
}
}
#pragma warning ( default : 4100 )
/////////////////////////////////////////////////////////////////////////////
#pragma warning ( default : 4711 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -