设为首页 加入收藏

TOP

VC创建动态效果窗口
2013-10-17 08:59:29 来源: 作者: 【 】 浏览:119
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获取系统特殊路径的方法 下一篇C++面试中string类的一种正确写法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: