其他语言

位置:IT落伍者 >> 其他语言 >> 浏览文章

Visual C++设计超强仿QQ自动伸缩窗口[3]


发布日期:2021年06月21日
 
Visual C++设计超强仿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 (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);

}

[] [] [] []

               

上一篇:Visual C++设计超强仿QQ自动伸缩窗口[1]

下一篇:Visual C++设计超强仿QQ自动伸缩窗口[4]