VisualC++設(shè)計超強仿QQ自動伸縮窗口(3)

字號:

代碼四
    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_;}else if(curPos.y >= (screenHeight - INTERVAL - m_taskBarHeight)){ //粘附在下邊pRect->top = screenHeight - m_taskBarHeight - height;pRect->bottom = screenHeight - m_taskBarHeight;m_hideMode = HM_BOTTOM;}else if (curPos.x < INTERVAL){ //粘附在左邊 if(!m_isSizeChanged){CRect tRect;GetWindowRect(tRect);m_oldWndHeight = tRect.Height(); }pRect->right = width;pRect->left = 0;pRect->top = -m_edgeHeight;pRect->bottom = screenHeight - m_taskBarHeight;m_isSizeChanged = TRUE;m_hideMode = HM_LEFT;}else if(curPos.x >= (screenWidth - INTERVAL)){ //粘附在右邊if(!m_isSizeChanged){CRect tRect;GetWindowRect(tRect);m_oldWndHeight = tRect.Height(); }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){ //如果收縮到兩邊,則拖出來后會變回原來大小//在"拖動不顯示窗口內(nèi)容下"只有光柵變回原來大小pRect->bottom = pRect->top + m_oldWndHeight;m_isSizeChanged = FALSE;}if(m_isSetTimer){ //如果Timer開啟了,則關(guān)閉之if(KillTimer(1) == 1)m_isSetTimer = FALSE;}m_hideMode = HM_NONE;GetDlgItem(IDC_TIMER)->SetWindowText("Timer off");}}
    收縮模式和位置決定后,剩下的工作就由最后兩個核心函數(shù)完成了:實現(xiàn)收縮的DoHide(),實現(xiàn)伸展的DoShow()。在這兩個過程中m_hsFinished,m_hiding 這兩個變量起到很重要的控制作用。由于伸縮過程沒完成時,hsFinished始終為FALSE,所以Timer 2 不會關(guān)閉,于是在OnTimer中會重復(fù)調(diào)用這兩個函數(shù)之一,在這兩個函數(shù)體內(nèi),窗口位置有規(guī)律地遞減或遞增就可以達到QQ的“抽屜”效果了,有趣的是即使伸縮過程還沒完成,你也可以在這個過程中改變m_hiding這個值來決定他是伸還是縮,正如QQ一樣。你可以把Timer 2 的事件間隔調(diào)大一點,然后在窗口伸縮時,鼠標來回地進出窗口就會很容易看到這樣有趣的效果(還沒縮進去又被拉了出來,或者還沒拉出來又縮進去了)。