在实现定时对话框的操作过程中,我们可以在对话框的显示以及退出过程中,加入渐变过程,
void CMsgWnd::CreateMsgWindow()
{
// RECT rect;
// SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
// int y=rect.bottom-rect.top;
// int x=rect.right-rect.left;
// x=x-WIN_WIDTH;
// y=y-WIN_HEIGHT;
CreateEx(0,
AfxRegisterWndClass(
0,
::LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_HAND_1)),(HBRUSH)(COLOR_DESKTOP+1),NULL),
"",
WS_POPUP|WS_EX_TOPMOST,
0,
0,
0,//bmBitmap.bmWidth, //Bitmap Width = Splash Window Width
0,//bmBitmap.bmHeight, //Bitmap Height = Splash Window Height
NULL,//AfxGetMainWnd()->GetSafeHwnd(),
NULL,
NULL);
SetTimer(ID_TIMER_POP_WINDOW,20,NULL);
}
创建窗口,这里窗口大小为0,并设置定时器,在定时器中对对话框的显示以及关闭作处理。
void CMsgWnd::OnTimer(UINT nIDEvent)
{
static int nHeight=0;
int cy=GetSystemMetrics(SM_CYSCREEN);
int cx=GetSystemMetrics(SM_CXSCREEN);
RECT rect;
SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
int y=rect.bottom-rect.top;
int x=rect.right-rect.left;
x=x-WIN_WIDTH;
switch(nIDEvent)
{
case ID_TIMER_POP_WINDOW:
if(nHeight<=WIN_HEIGHT)
{
++nHeight;
MoveWindow(x,
y-nHeight,
WIN_WIDTH,
WIN_HEIGHT);
Invalidate(FALSE);
}
else
{
KillTimer(ID_TIMER_POP_WINDOW);
SetTimer(ID_TIMER_DISPLAY_DELAY,5000,NULL);
}
break;
case ID_TIMER_CLOSE_WINDOW:
if(nHeight>=0)
{
nHeight--;
MoveWindow(x,
y-nHeight,
WIN_WIDTH,
nHeight);
}
else
{
KillTimer(ID_TIMER_CLOSE_WINDOW);
SendMessage(WM_CLOSE);
}
break;
case ID_TIMER_DISPLAY_DELAY:
KillTimer(ID_TIMER_DISPLAY_DELAY);
SetTimer(ID_TIMER_CLOSE_WINDOW,20,NULL);
break;
}
CWnd::OnTimer(nIDEvent);
}
显示时,逐渐改变窗口的纵坐标,知道完全显示,然后设置延时定时器,在延时定时器中逐渐改变对话框大小,直到消失。