Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14497248
  • 博文数量: 5645
  • 博客积分: 9880
  • 博客等级: 中将
  • 技术积分: 68081
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-28 13:35
文章分类

全部博文(5645)

文章存档

2008年(5645)

我的朋友

分类:

2008-04-28 20:52:57

下载本文示例代码
  在Windows应用程序中,对话框是应用最广泛也是比较难控制其风格(外表)的一类窗口。相信用过Windows 的朋友在享受其强大功能的同时,一定也为它所提供的具有立体感的界面而感叹吧。通常情况下,对话框的弹出和消隐都是瞬时的,下面将介绍如何实现对话框的动画弹出和消隐,增强程序的美观性。  请按以下步骤实现:  第一步:生成我们的工程(基于对话框)FlashDlg,所有的选项都取默认值,在对话框上随意添加几个控件。  第二步:在对话框的类头文件中定义如下变量,如下: CPoint point;int nWidth,nHeight;int dx,dy;int dx1,dy1;  第三步:在OnInitDialog()中添加如下代码: BOOL CFlashDlgDlg::OnInitDialog(){ CDialog::OnInitDialog();  CRect dlgRect;  GetWindowRect(dlgRect);  CRect desktopRect;  GetDesktopWindow()->GetWindowRect(desktopRect); MoveWindow(   (desktopRect.Width() - dlgRect.Width()) / 2,   (desktopRect.Height() - dlgRect.Height()) / 2,    0,    0 );  nWidth=dlgRect.Width();  nHeight=dlgRect.Height();  dx=2; dy=4;  dx1=2; dy1=2; SetTimer(1,10 , NULL);  return TRUE; }  第四步:添加OnTimer函数,添加如下代码: void CFlashDlgDlg::OnTimer(UINT nIDEvent) {// TODO: Add your message handler code here and/or call defaultCRect dlgRect;GetWindowRect(dlgRect);CRect desktopRect;GetDesktopWindow()->GetWindowRect(desktopRect);if(nIDEvent == 1){MoveWindow((-dx desktopRect.Width() - dlgRect.Width()) / 2,(-dy desktopRect.Height() - dlgRect.Height()) / 2, dx dlgRect.Width(), dy dlgRect.Height() );if(dlgRect.Width() >=nWidth) dx=0; // do not over growif(dlgRect.Height() >=nHeight)dy=0; // do not over growif((dlgRect.Width() >=nWidth) && (dlgRect.Height() >=nHeight))KillTimer(1); //Stop the timer}if((dlgRect.Width() >=nWidth) && (dlgRect.Height() >=nHeight))KillTimer(1); //Stop the timerif(nIDEvent == 2){MoveWindow(( dx desktopRect.Width() - dlgRect.Width()) / 2,( dy desktopRect.Height() - dlgRect.Height()) / 2,-dx1 dlgRect.Width(),-dy1 dlgRect.Height() );if(dlgRect.Width() <= 0) dx1=0; // do not over growif(dlgRect.Height() <= 0 )dy1=0; // do not over growif((dlgRect.Width() <= 0 ) && (dlgRect.Height() <=0)){KillTimer(2); //Stop the timerCDialog::OnOK();}}CDialog::OnTimer(nIDEvent);}  好了,对话框的动画出现和消隐实现了,运行程序我们会发现对话框平滑的划出,关闭程序我们会发现对话框平滑的消失。   在Windows应用程序中,对话框是应用最广泛也是比较难控制其风格(外表)的一类窗口。相信用过Windows 的朋友在享受其强大功能的同时,一定也为它所提供的具有立体感的界面而感叹吧。通常情况下,对话框的弹出和消隐都是瞬时的,下面将介绍如何实现对话框的动画弹出和消隐,增强程序的美观性。  请按以下步骤实现:  第一步:生成我们的工程(基于对话框)FlashDlg,所有的选项都取默认值,在对话框上随意添加几个控件。  第二步:在对话框的类头文件中定义如下变量,如下: CPoint point;int nWidth,nHeight;int dx,dy;int dx1,dy1;  第三步:在OnInitDialog()中添加如下代码: BOOL CFlashDlgDlg::OnInitDialog(){ CDialog::OnInitDialog();  CRect dlgRect;  GetWindowRect(dlgRect);  CRect desktopRect;  GetDesktopWindow()->GetWindowRect(desktopRect); MoveWindow(   (desktopRect.Width() - dlgRect.Width()) / 2,   (desktopRect.Height() - dlgRect.Height()) / 2,    0,    0 );  nWidth=dlgRect.Width();  nHeight=dlgRect.Height();  dx=2; dy=4;  dx1=2; dy1=2; SetTimer(1,10 , NULL);  return TRUE; }  第四步:添加OnTimer函数,添加如下代码: void CFlashDlgDlg::OnTimer(UINT nIDEvent) {// TODO: Add your message handler code here and/or call defaultCRect dlgRect;GetWindowRect(dlgRect);CRect desktopRect;GetDesktopWindow()->GetWindowRect(desktopRect);if(nIDEvent == 1){MoveWindow((-dx desktopRect.Width() - dlgRect.Width()) / 2,(-dy desktopRect.Height() - dlgRect.Height()) / 2, dx dlgRect.Width(), dy dlgRect.Height() );if(dlgRect.Width() >=nWidth) dx=0; // do not over growif(dlgRect.Height() >=nHeight)dy=0; // do not over growif((dlgRect.Width() >=nWidth) && (dlgRect.Height() >=nHeight))KillTimer(1); //Stop the timer}if((dlgRect.Width() >=nWidth) && (dlgRect.Height() >=nHeight))KillTimer(1); //Stop the timerif(nIDEvent == 2){MoveWindow(( dx desktopRect.Width() - dlgRect.Width()) / 2,( dy desktopRect.Height() - dlgRect.Height()) / 2,-dx1 dlgRect.Width(),-dy1 dlgRect.Height() );if(dlgRect.Width() <= 0) dx1=0; // do not over growif(dlgRect.Height() <= 0 )dy1=0; // do not over growif((dlgRect.Width() <= 0 ) && (dlgRect.Height() <=0)){KillTimer(2); //Stop the timerCDialog::OnOK();}}CDialog::OnTimer(nIDEvent);}  好了,对话框的动画出现和消隐实现了,运行程序我们会发现对话框平滑的划出,关闭程序我们会发现对话框平滑的消失。 下载本文示例代码


谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐谈对话框的动画弹出和动画消隐
阅读(101) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~