📄 screenadaptive.cpp
字号:
#include "ScreenAdaptive.h"
#include "Util.h"
void ScreenAdaptor::AdaptControl(HWND hwndDlg, UINT nIDAffectedCtl, SCREENADAPTOR_TYPE nType)
{
ASSERT(hwndDlg != NULL);
RECT rcClient;
::GetClientRect(hwndDlg, &rcClient);
//rcClient.bottom -= GetSipHieght();
// Verify the affected control and obtain its rect
HWND hwndCtl = ::GetDlgItem(hwndDlg, nIDAffectedCtl);
ASSERT(hwndCtl != NULL);
RECT rcCtl;
::GetWindowRect(hwndCtl, &rcCtl);
rcCtl.top -= IndicatorHieght();
rcCtl.bottom -= IndicatorHieght();
int nLeft, nTop, nWidth, nHeight;
nLeft = rcCtl.left;
nTop = rcCtl.top;
nWidth = rcCtl.right - rcCtl.left;
nHeight = rcCtl.bottom - rcCtl.top;
if(nType & SCREENADAPTOR_ALIGN_LEFT)
{
nWidth +=(nLeft);
nLeft = 0;
}
if(nType & SCREENADAPTOR_ALIGN_RIGHT)
{
nWidth =rcClient.right - nLeft;
}
if(nType & SCREENADAPTOR_ALIGN_TOP)
{
nHeight +=nTop;
nTop = 0;
}
if(nType & SCREENADAPTOR_ALIGN_BOTTOM)
{
nHeight =rcClient.bottom -GetSipHieght(rcCtl)- nTop;
}
else if(nType & SCREENADAPTOR_DOCK_LEFT)
{
nLeft = 0;
}else if(nType & SCREENADAPTOR_DOCK_RIGHT)
{
nLeft = rcClient.right - nWidth;
}else if(nType & SCREENADAPTOR_DOCK_TOP)
{
nTop = 0;
}else if(nType & SCREENADAPTOR_DOCK_BOTTOM)
{
nTop = rcClient.bottom - nHeight;
}
else if(nType & SCREENADAPTOR_DOCK_FILL)
{
nLeft = 0;
nTop = 0;
nWidth = rcClient.right - rcClient.left;
nHeight = rcClient.bottom - rcClient.top;
}
else
{
}
::MoveWindow(hwndCtl, nLeft , nTop, nWidth, nHeight, TRUE);
}
void ScreenAdaptor::OptimizeHeight(HWND hwndDlg, UINT nIDAffectedCtl)
{
ASSERT(hwndDlg != NULL);
RECT rcClient;
::GetClientRect(hwndDlg, &rcClient);
// Verify the affected control and obtain its rect
HWND hwndCtl = ::GetDlgItem(hwndDlg, nIDAffectedCtl);
ASSERT(hwndCtl != NULL);
RECT rcCtl;
::GetWindowRect(hwndCtl, &rcCtl);
POINT ptMoveTo;
ptMoveTo.x = rcCtl.left;
ptMoveTo.y = rcCtl.top;
::ScreenToClient(hwndDlg, &ptMoveTo);
::SetWindowPos(hwndCtl, NULL, 0, 0,
rcCtl.right - rcCtl.left,
rcClient.bottom - rcClient.top - ptMoveTo.y - rcCtl.left,
SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
}
void ScreenAdaptor::MakeSameSize(HWND hwndDlg, SCREENADAPTOR_SIZE nType, int cAffectedCtls,
UINT nIDFixedCtl, UINT nIDAffectedCtl, ...)
{
ASSERT(hwndDlg != NULL);
ASSERT(cAffectedCtls > 0); // must have at least 1 movable control
// Verify the fixed control and obtain its rect
HWND hwndFixedCtl = ::GetDlgItem(hwndDlg, nIDFixedCtl);
ASSERT(hwndFixedCtl != NULL);
RECT rcFixed;
::GetWindowRect(hwndFixedCtl, &rcFixed);
// Initialize variable arguments.
va_list marker;
va_start(marker, nIDAffectedCtl);
UINT nIDCurrentCtl = nIDAffectedCtl;
while (cAffectedCtls-- > 0)
{
// Verify the current movable control and obtain its rect
HWND hwndIDCurrent = ::GetDlgItem(hwndDlg, nIDCurrentCtl);
ASSERT(hwndIDCurrent != NULL);
RECT rcCurrent;
::GetWindowRect(hwndIDCurrent, &rcCurrent);
int nWidth, nHeight;
nWidth = rcCurrent.right - rcCurrent.left;
nHeight = rcCurrent.bottom - rcCurrent.top;
if(nType & SCREENADAPTOR_SIZE_WIDTH)
{
nWidth = rcFixed.right - rcFixed.left;
}
if(nType & SCREENADAPTOR_SIZE_HEIGHT)
{
nHeight = rcFixed.bottom - rcFixed.top;
}
::SetWindowPos(hwndIDCurrent, NULL, 0, 0, nWidth, nHeight,
SWP_NOMOVE|SWP_NOZORDER);
nIDCurrentCtl = va_arg(marker, UINT);
}
va_end(marker);
}
#define MIN_SPACE 3
void ScreenAdaptor::ArrangeControls(HWND hwndDlg, SCREENADAPTOR_ARRANGE nType, int cAffectedCtls, UINT nIDFixedCtl, UINT nIDAffectedCtl, ...)
{
ASSERT(hwndDlg != NULL);
//ASSERT(cAffectedCtls > 0); // must have at least 1 movable control
RECT rcClient;
::GetClientRect(hwndDlg, &rcClient);
//rcClient.bottom -= GetSipHieght();
// Verify the fixed control and obtain its rect
HWND hwndFixedCtl = ::GetDlgItem(hwndDlg, nIDFixedCtl);
ASSERT(hwndFixedCtl != NULL);
RECT rcFixed;
::GetWindowRect(hwndFixedCtl, &rcFixed);
rcFixed.top -= IndicatorHieght();
rcFixed.bottom -= IndicatorHieght();
// Initialize variable arguments.
BOOL nArrangeHV = (nType &SCREENADAPTOR_ARRANGE_HV)?TRUE:FALSE;
BOOL nArrangeLF = (nType &SCREENADAPTOR_ARRANGE_LF)?TRUE:FALSE;
BOOL nArrangeUD = (nType &SCREENADAPTOR_ARRANGE_UD)?TRUE:FALSE;
BOOL nArrangeCET = (nType &SCREENADAPTOR_ARRANGE_CENTER)?TRUE:FALSE;
int ntWidth = rcFixed.right-rcFixed.left, ntHeight = rcFixed.bottom - rcFixed.top,skip = MIN_SPACE;
int counter = cAffectedCtls;
UINT nIDCurrentCtl = 0;
va_list marker;
va_start(marker, nIDAffectedCtl);
nIDCurrentCtl = nIDAffectedCtl;
while (counter-- > 0)
{
// Verify the current movable control and obtain its rect
HWND hwndIDCurrent = ::GetDlgItem(hwndDlg, nIDCurrentCtl);
ASSERT(hwndIDCurrent != NULL);
RECT rcCurrent;
::GetWindowRect(hwndIDCurrent, &rcCurrent);
if(nArrangeHV)
ntWidth += MIN_SPACE+(rcCurrent.right - rcCurrent.left);
else
ntHeight+= MIN_SPACE+(rcCurrent.bottom - rcCurrent.top);
nIDCurrentCtl = va_arg(marker, UINT);
}
va_end(marker);
if(nArrangeHV)
{
if(nArrangeLF)
skip += (rcFixed.right - rcClient.left - ntWidth)/(cAffectedCtls);
else
skip += (rcClient.right - rcFixed.left - ntWidth)/(cAffectedCtls);
if(nArrangeCET)
{
skip = MIN_SPACE + (rcClient.right - rcClient.left - ntWidth)/(cAffectedCtls+2);
}
}
else
{
if(nArrangeUD)
skip += (rcFixed.bottom - rcClient.top - ntHeight)/(cAffectedCtls);
else
skip += (rcClient.bottom - rcFixed.top - ntHeight)/(cAffectedCtls);
if(nArrangeCET)
skip = MIN_SPACE +(rcClient.bottom - rcClient.top - ntHeight)/(cAffectedCtls+2);
}
if(nArrangeCET)
{
int l,t,w,h;
l = rcFixed.left;
t = rcFixed.top;
w = rcFixed.right - l;
h = rcFixed.bottom - t;
if(nArrangeHV)
{
if(nArrangeLF)
l = rcClient.right - skip -w;
else
l = rcClient.left +skip ;
}
else
{
if(!nArrangeUD)
t = rcClient.top +skip;
else
t = rcClient.bottom - skip;
}
rcFixed.left = l;
rcFixed.right = l+w;
rcFixed.top = t;
rcFixed.bottom = t+h;
::MoveWindow(hwndFixedCtl, l , t, w, h, TRUE);
}
if(skip <0)skip = 0;
va_start(marker, nIDAffectedCtl);
nIDCurrentCtl = nIDAffectedCtl;
counter = cAffectedCtls;
int cskip = 0;
int x= (!nArrangeLF)?rcFixed.right:rcFixed.left ;
int y =(!nArrangeUD)?rcFixed.bottom:rcFixed.top ;
while (counter-- > 0)
{
// Verify the current movable control and obtain its rect
HWND hwndIDCurrent = ::GetDlgItem(hwndDlg, nIDCurrentCtl);
ASSERT(hwndIDCurrent != NULL);
RECT rcCurrent;
::GetWindowRect(hwndIDCurrent, &rcCurrent);
int l,t,w,h;
rcCurrent.top = rcCurrent.top -IndicatorHieght();
rcCurrent.bottom = rcCurrent.bottom -IndicatorHieght();
l = rcCurrent.left;
t = rcCurrent.top;
w = rcCurrent.right - l;
h = rcCurrent.bottom - t;
if(nArrangeHV)
{
if(nArrangeLF)
{
l= x - w-skip;
x =l ;
}
else
{
l = x+skip;
x = l+w;
}
t = rcFixed.top;
}
else
{
if(nArrangeUD)
{
t = y - skip;
y = t-h;
}
else
{
t = y+skip;
y =t +h ;
}
l = rcFixed.left;
}
::MoveWindow(hwndIDCurrent, l , t, w, h, TRUE);
nIDCurrentCtl = va_arg(marker, UINT);
}
va_end(marker);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -