CRect rc;
int moves = 10; //动画滚动窗体的步数
int xStep, yStep;
int xEnd, yEnd;
int width;
int height;
GetWindowRect(&rc);
width = rc.right - rc.left;
height = rc.bottom - rc.top;
//下边判断窗体该如何移动,由停靠方式决定
switch (alignType)
{
case ALIGN_TOP:
{
//向上隐藏
xStep = 0;
xEnd = rc.left;
if (hide)
{
yStep = -rc.bottom / moves;
yEnd = -height + NEAR_SIDE ;
}
else
{
yStep = -rc.top / moves;
yEnd = 0;
}
break;
}
case ALIGN_LEFT:
{
//向左隐藏
yStep = 0;
yEnd = rc.top;
if (hide)
{
xStep = -rc.right / moves;
xEnd = -width + NEAR_SIDE;
}
else
{
xStep = -rc.left / moves;
xEnd = 0;
}
break;
}
case ALIGN_RIGHT:
{
//向右隐藏
yStep = 0;
yEnd = rc.top;
if (hide)
{
xStep = (ScreenX - rc.left) / moves;
xEnd = ScreenX - NEAR_SIDE;
}
else
{
xStep = (ScreenX - rc.right) / moves;
xEnd = ScreenX - width;
}
break;
}
default:
{
return;
}
}
//动画滚动窗体.
for (int i = 0; i < moves; i++)
{
rc.left += xStep;
rc.top += yStep;
SetWindowPos(NULL, rc.left, rc.top, width, height,SWP_NOSIZE | SWP_NOSENDCHANGING);
RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
//UpdateWindow();
Sleep(2);
}
SetWindowPos(&wndTopMost, xEnd, yEnd,width, height, SWP_NOSIZE);
//如果窗体已被显示,设置定时器,监视鼠标
if (!hide)
{
SetTimer(WM_TIMER, 50, NULL);
}