代碼四
void CQQHideWndDlg::FixMoving(UINT fwSide
LPRECT pRect)
{
POINT curPos;
GetCursorPos(&curPos);
INT screenHeight = GetSystemMetrics(SM_CYSCREEN);
INT screenWidth = GetSystemMetrics(SM_CXSCREEN);
INT height = pRect>bottom pRect >top;
INT width = pRect>right pRect >left; if (curPos
y <= INTERVAL)
{ //粘附在上邊
pRect>bottom = height m_edgeHeight;
pRect>top = m_edgeHeight;
m_hideMode = HM_TOP;
}
else if(curPosy >= (screenHeight INTERVAL m_taskBarHeight))
{ //粘附在下邊
pRect>top = screenHeight m_taskBarHeight height;
pRect>bottom = screenHeight m_taskBarHeight;
m_hideMode = HM_BOTTOM;
}
else if (curPosx < INTERVAL)
{ //粘附在左邊
if(!m_isSizeChanged)
{
CRect tRect;
GetWindowRect(tRect);
m_oldWndHeight = tRectHeight();
}
pRect>right = width;
pRect>left = ;
pRect>top = m_edgeHeight;
pRect>bottom = screenHeight m_taskBarHeight;
m_isSizeChanged = TRUE;
m_hideMode = HM_LEFT;
}
else if(curPosx >= (screenWidth INTERVAL))
{ //粘附在右邊
if(!m_isSizeChanged)
{
CRect tRect;
GetWindowRect(tRect);
m_oldWndHeight = tRectHeight();
}
pRect>left = screenWidth width;
pRect>right = screenWidth;
pRect>top = m_edgeHeight;
pRect>bottom = screenHeight m_taskBarHeight;
m_isSizeChanged = TRUE;
m_hideMode = HM_RIGHT;
}
else
{ //不粘附
if(m_isSizeChanged)
{ //如果收縮到兩邊則拖出來後會變回原來大小
//在拖動不顯示窗口內容下 只有光柵變回原來大小
pRect>bottom = pRect >top + m_oldWndHeight;
m_isSizeChanged = FALSE;
}
if(m_isSetTimer)
{ //如果Timer開啟了則關閉之
if(KillTimer() == )
m_isSetTimer = FALSE;
}
m_hideMode = HM_NONE;
GetDlgItem(IDC_TIMER)>SetWindowText( Timer off );
}
}
收縮模式和位置決定後
代碼五
void CQQHideWndDlg::DoHide()
{
if(m_hideMode == HM_NONE)
return;CRect tRect;
GetWindowRect(tRect);INT height = tRect
Height();
INT width = tRectWidth(); INT steps =
; switch(m_hideMode)
{
case HM_TOP:
steps = height/HS_STEPS;
tRectbottom = steps;
if(tRectbottom <= m_edgeWidth)
{ //你可以把下面一句替換上面的+=| =steps 達到取消抽屜效果
//更好的辦法是添加個BOOL值來控制其他case同樣
tRectbottom = m_edgeWidth;
m_hsFinished = TRUE; //完成隱藏過程
}
tRecttop = tRect bottom height;
break;
case HM_BOTTOM:
steps = height/HS_STEPS;
tRecttop += steps;
if(tRecttop >= (GetSystemMetrics(SM_CYSCREEN) m_edgeWidth))
{
tRecttop = GetSystemMetrics(SM_CYSCREEN) m_edgeWidth;
m_hsFinished = TRUE;
}
tRectbottom = tRect top + height;
break;
case HM_LEFT:
steps = width/HS_STEPS;
tRectright = steps;
if(tRectright <= m_edgeWidth)
{
tRectright = m_edgeWidth;
m_hsFinished = TRUE;
}
tRectleft = tRect right width;
tRecttop = m_edgeHeight;
tRectbottom = GetSystemMetrics(SM_CYSCREEN) m_taskBarHeight;
break;
case HM_RIGHT:
steps = width/HS_STEPS;
tRectleft += steps;
if(tRectleft >= (GetSystemMetrics(SM_CXSCREEN) m_edgeWidth))
{
tRectleft = GetSystemMetrics(SM_CXSCREEN) m_edgeWidth;
m_hsFinished = TRUE;
}
tRectright = tRect left + width;
tRecttop = m_edgeHeight;
tRectbottom = GetSystemMetrics(SM_CYSCREEN) m_taskBarHeight;
break;
default:
break;
}SetWindowPos(&wndTopMost
tRect);
}
[
From:http://tw.wingwit.com/Article/program/net/201311/15313.html