界面编程学习-自动伸缩的对话框

来源:互联网 发布:怎么还原数据库 编辑:程序博客网 时间:2024/04/30 20:48
模仿一些杀毒软件的提示对话框
void CDlgNewMsg::OnTimer(UINT nIDEvent)
{
    
//获得此时窗口的实际大小
    CRect dlgRect;
    GetWindowRect(dlgRect);
    
//获得桌面的大小
    CRect desktopRect;
    GetDesktopWindow()
->GetWindowRect(desktopRect);
    
//如果是窗口弹出过程,则逐渐增大窗口
    if(nIDEvent == 1)
    
{
        MoveWindow(desktopRect.Width() 
- dlgRect.Width(),
            dlgRect.top 
- m_nDy - m_nDt, 
            dlgRect.Width(),
            m_nDy 
+ dlgRect.Height());

        m_nDt 
= 0
        
//不要超过窗口预设的高度
        if(dlgRect.Height() >= m_nHeight)
            m_nDy
=0;
        
//停止变化,关闭定时器1
        if(dlgRect.Height() >= m_nHeight)
        
{
            SetTimer(
25000, NULL);
            KillTimer(
1);
        }

    }


    
// 开始计时自动关闭窗口
    if (nIDEvent == 2)
    
{
        SetTimer(
310, NULL);
        KillTimer(
2);
    }


    
//如果是窗口关闭过程,则逐渐缩小窗口
    if(nIDEvent == 3)
    
{
        MoveWindow(desktopRect.Width() 
- dlgRect.Width(),
            dlgRect.top 
+ m_nDy1, 
            dlgRect.Width(),
            dlgRect.Height() 
- m_nDy1);

        
//当高度等于零后高度就不在变化
        if(dlgRect.Height() <= 0 )
            m_nDy1
=0
        
//停止变化,关闭定时器2,并且关闭窗口
        if(dlgRect.Height() <= 0)
        
{
            KillTimer(
3);
            UpdateData();
            CString iniPath 
= CCommon::GetAppPath() + "用户配置.ini";
            WritePrivateProfileString(
"显示消息""模式", m_bNextNote ? "":"", iniPath);
            CDialog::OnOK();
        }

    }


    CDialog::OnTimer(nIDEvent);
}