设为首页 加入收藏

TOP

VC创建动态效果窗口
2014-11-23 20:26:22 】 浏览:308
Tags:创建 动态 效果 窗口

此程序可实现像流光一样开始运行时窗口出现的效果。大概就是一运行,从小变到,直至显示整个程序。此效果我认为还是很漂亮的。主要运用的函数是:MoveWindow(); ,然后调用OnTimer(); 来实现的。

第一步:
在程序头文件定义全局变量:


int m_nWidth,m_nHeight;
int m_nDx,m_nDy;
int m_nDx1,m_nDy1;


第二步:
在CMyDlg::OnInitDialog() 函数中加入如下代码,用于实现动态效果:


CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect);
MoveWindow((desktopRect.Width()-dlgRect.Width())/2,(desktopRect.Height()-dlgRect.Height())/2,0,0);
m_nWidth=dlgRect.Width();
m_nHeight=dlgRect.Height();
m_nDx=6;
m_nDy=8;
m_nDx1=6;
m_nDy1=6;
SetTimer(1,10,NULL);


第三步:
在CMyDlg::OnClose() 函数中加入如下代码,实现关闭动态效果:


SetTimer(2,10,NULL);


在OnClose()函数中,要去掉 CDialog::OnClose(); 此句。


第四步:
详细的调用函数:CMyDlg::OnTimer(UINT nIDEvent)


CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect);
if(nIDEvent==1)
{
MoveWindow((-m_nDx+desktopRect.Width()-dlgRect.Width())/2,(-m_nDy+desktopRect.Height()-dlgRect.Height())/2,+m_nDx+dlgRect.Width(),+m_nDy+dlgRect.Height());
if(dlgRect.Width()>=m_nWidth)
m_nDx=0;
if(dlgRect.Height()>=m_nHeight)
m_nDy=0;
if((dlgRect.Width()>=m_nWidth)&&(dlgRect.Height()>=m_nHeight))
KillTimer(1);
}
if((dlgRect.Width()>=m_nWidth)&&(dlgRect.Height()>=m_nHeight))
KillTimer(1);
if(nIDEvent==2)
{
MoveWindow((+m_nDx+desktopRect.Width()-dlgRect.Width())/2,(+m_nDy+desktopRect.Height()-dlgRect.Height())/2,-m_nDx1+dlgRect.Width(),-m_nDy1+dlgRect.Height());
if(dlgRect.Width()<=0)
m_nDx1=0;
if(dlgRect.Height()<=0)
m_nDy1=0;
if((dlgRect.Width()<=0)&&(dlgRect.Height()<=0))
{
KillTimer(2);
CDialog::OnOK();
}
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇用VC生成最小的EXE文件 下一篇VC++实现镜像劫持(360保险箱启动..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目