




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、delphi实现延时自动关闭对话框*一种自动关闭对话框的简单方法使用方法:打开对话框前调用SetDlgAutoClose参数1:设定多长时间后关闭参数2:是否在对话框标题栏进行倒计时提示取消自动关闭调用ResetDlgAutoCloseunit*TimerDlg;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,ExtCtrls;/如果指定的时间没有操作对话框,则自动关闭procedureResetDlgAutoClose;procedureSetDlgAutoClose(nTime:
2、Integer;ADoHint:Boolean=False);implementation*如果对话框被打开,贝U在指定时间后关闭,并在标题栏进行提示varnWndCount:Integer=0;SavWnds,SavWnds2:arrayofTHandle;hDlgWnd:THandle=0;hTimerk:Integer=0;nTimerTick:Integer=0;nLastTrk:Integer=0;nDoHint:Integer=0;nCapCt:Integer=0;nSavCapt:String=''fTimer1:TTimer=nil;functionMyEnum
3、Proc(hWnd:THandle;lParam:Integer):Boolean;stdcall;varn:Integer;beginResult:=True;iflParam=0thenbeginifnotIsWindowEnabled(hWnd)thenExit;ifnotIsWindowVisible(hWnd)thenExit;end;n:=(nWndCount+10)div10*10;SetLength(SavWnds,n);SavWndsnWndCount:=hWnd;Inc(nWndCount);end;procedureMyTimerProc(hWnd:THandle;uMs
4、g:Integer;idEvent:Integer;dwTime:Integer);vari,t:Integer;functionFindInArray(ar:arrayofTHandle;hd:THandle):Boolean;vart:Integer;beginResult:=False;fort:=Low(ar)toHigh(ar)dobeginResult:=art=hd;ifResultthenBreak;end;end;beginif(hDlgWnd=0)and(SavWnds=nil)and(SavWnds2nil)thenbeginnWndCount:=0;EnumThread
5、Windows(GetCurrentThreadId,MyEnumProc,0);SetLength(SavWnds,nWndCount);fori:=Low(SavWnds)toHigh(SavWnds)dobeginifnotFindInArray(SavWnds2,SavWndsi)thenbeginifSavWndsi=GetActiveWindowthenbeginhDlgWnd:=SavWndsi;end;end;end;ifhDlgWnd=0thenResetDlgAutoClose;nLastTrk:=GetTickCount;SetLength(nSavCapt,500);t
6、:=GetWindowText(hDlgWnd,PChar(nSavCapt),500);SetLength(nSavCapt,t);nCapCt:=0;endelseif(hDlgWnd0)thenifnotIsWindow(hDlgWnd)ornotIsWindowVisible(hDlgWnd)ornotIsWindowEnabled(hDlgWnd)thenbeginResetDlgAutoClose;Exit;end;t:=GetTickCount;t:=(nTimerTick-(t-nLastTrk)-1);ift0)thenbegint:=(t+1000)div1000;ifnC
7、apCttthenbeginSetWindowText(hDlgWnd,PChar(Format('(%d)%2s%s',t,'',nSavCapt);nCapCt:=t;end;end;end;end;procedureTimerFunc(Sender:TObject);MyTimerProc(0,0,0,0);end;procedureSetDlgAutoClose(nTime:Integer;ADoHint:Boolean=False);varFakeEvt:TNotifyEvent;Ptrs:array1.2ofPointerabsoluteFakeEv
8、t;beginResetDlgAutoClose;nWndCount:=0;EnumThreadWindows(GetCurrentThreadId,MyEnumProc,1);SetLength(SavWnds,nWndCount);SavWnds2:=SavWnds;SavWnds:=nil;ifnotAssigned(fTimer1)thenbeginfTimer1:=TTimer.Create(Application);Ptrs2:=nil;Ptrs1:=TimerFunc;fTimer1.OnTimer:=FakeEvt;fTimer1.Interval:=100;fTimer1.E
9、nabled:=True;end;nLastTrk:=GetTickCount;nDoHint:=Ord(ADoHint);nTimerTick:=nTime;end;procedureResetDlgAutoClose;beginifhDlgWnd0thenbeginSetWindowText(hDlgWnd,PChar(nSavCapt);end;ifAssigned(fTimer1)thenFreeAndNil(fTimer1);nWndCount:=0;hDlgWnd:=0;SavWnds:=nil;SavWnds2:=nil;nTimerTick:=0;end;end.测试proce
10、dureTForm1.Button1Click(Sender:TObject);beginSetDlgAutoClose(15*1000,True);ShowMessage('Thismessageboxwillcloseautomatically,+#13#10+'afterfifteenseconds.');end;procedureTForm1.Button3Click(Sender:TObject);beginSetDlgAutoClose(8000,Sender=Button3);MessageBox(Handle,PChar('这是一个测试例子'+#13#10+'此消息框将在8秒钟后自动关闭'+#13#10+'只需要在调用消息框和对话框之前调用一个函数+#13#10+'就可以方便的实现这种效果'),'定时自动关闭的消息框',MB_ICONINFORMATIONorMB_OKCANCEL);end;procedureTForm1.Button2Click(Sender:TObject);vardlg:TDlgTest;beginSetD
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025育婴师考试解析试题及答案
- 2025年育婴师考试对儿童发展的影响分析试题及答案
- 中小学教师资格笔试学习机会的利用与有效拓展研究试题及答案
- 会计师事务所工作试题及答案
- 2025年育婴师社会支持网络试题及答案
- 2024年网络规划设计师应试心得体会试题及答案
- 2024年图书馆管理软件应用试题及答案
- 2025税务师备考准备分析试题及答案
- 2025年成人高考语文高频考点速记题库-文言文阅读理解与技巧试题
- 乡村全科助理医师考试学习资源试题及答案
- 防流感班会课件
- 2025年春季四年级下册语文第15课《白鹅》课件(统编版)
- 2024北京市大兴初二(下)期中数学试卷及答案
- JGT266-2011 泡沫混凝土标准规范
- 中央八项规定实施细则解读课件
- 宿舍教室报修维修登记表
- 二正丁胺MSDS危险化学品安全技术说明书
- 实际问题与二元一次方程组说课稿12
- 上海名师应彩云_大班综合活动+百家姓
- 《信号与系统》讲义教案-第2章 信号与系统的时域分析
- 外周动脉检测分析术
评论
0/150
提交评论