熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

Visual C++設計超強仿QQ自動伸縮窗口[3]

2022-06-13   來源: .NET編程 

  代碼四

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 (curPosy <= 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);
}
}

  收縮模式和位置決定後剩下的工作就由最後兩個核心函數完成了實現收縮的DoHide()實現伸展的DoShow()在這兩個過程中m_hsFinishedm_hiding 這兩個變量起到很重要的控制作用由於伸縮過程沒完成時hsFinished始終為FALSE所以Timer 不會關閉於是在OnTimer中會重復調用這兩個函數之一在這兩個函數體內窗口位置有規律地遞減或遞增就可以達到QQ的抽屜效果了有趣的是即使伸縮過程還沒完成你也可以在這個過程中改變m_hiding這個值來決定他是伸還是縮正如QQ一樣你可以把Timer 的事件間隔調大一點然後在窗口伸縮時鼠標來回地進出窗口就會很容易看到這樣有趣的效果(還沒縮進去又被拉了出來或者還沒拉出來又縮進去了)

  代碼五

void CQQHideWndDlg::DoHide()
{
if(m_hideMode == HM_NONE)
return;

CRect tRect;
GetWindowRect(tRect);

INT height = tRectHeight();
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 = tRectbottom 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 = tRecttop + height;
break;
case HM_LEFT:
steps = width/HS_STEPS;
tRectright = steps;
if(tRectright <= m_edgeWidth)
{
tRectright = m_edgeWidth;
m_hsFinished = TRUE;
}
tRectleft = tRectright 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 = tRectleft + width;
tRecttop = m_edgeHeight;
tRectbottom = GetSystemMetrics(SM_CYSCREEN) m_taskBarHeight;
break;
default:
break;
}

SetWindowPos(&wndTopMosttRect);
}

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15313.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.