当前位置:编程学习 > VC++ >>

VC创建动态效果窗口

此程序可实现像流光一样开始运行时窗口出现的效果。大概就是一运行,从小变到,直至显示整个程序。此效果我认为还是很漂亮的。主要运用的函数是: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 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,