版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年广东省台山市高考历史自测卷含答案(B卷)
- 2026 江苏 退役军人岗结构化面试考前模拟训练卷
- 2026 湖南 事业编政府服务中心高频强化训练卷含解析
- 2026 山东事业编综合岗结构化面试高频强化训练卷
- 2026下半年初中生物教资面试生态系统能量流动题库
- 2026下半年高中英语教资面试口语专项真题
- 2025年福建省长乐市高二生物下册期末考试模拟检测卷附完整答案【典优】
- 2026年江苏省海门市高二历史上册期末考试检测卷带答案(基础题)
- 2026中国电网数字化转型升级关键技术装备市场调研
- 2026新材料技术突破及市场应用前景预测报告
- 糖尿病自我管理行为量表SDSCA
- 学校各班级评分评比各项细则
- 2026特种作业人员培训
- 2026-2030洗发护发品市场发展现状调查及供需格局分析预测报告
- 2026年检察院书记员招聘笔试核心考点
- (2026年)危重病人的病情观察及护理课件
- 桩基检测监理实施细则
- 厦门大学介绍
- 国家安全法培训课件
- 低温冰雪天气防范课件
- (一模)柳州市2026届高三第一次模拟考试化学试卷(含答案)
评论
0/150
提交评论