时间: 2021-07-31 作者:daque
在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);} 好了,对话框的动画展示和消隐实行了,运路途序咱们会创造对话框光滑的划出,封闭步调咱们会创造对话框光滑的消逝。