Delphi调用IProgressDialog接口示例
来源:互联网 发布:hadoop 2.8.0 windows 编辑:程序博客网 时间:2024/05/16 02:59
IProgressDialog是Windows外壳提供的用于显示进度的对话框,包含文本提示及进度条,还可自动进行时间估算。
该接口主要包含以下方法:
HasUserCancelledChecks whether the user has canceled the operation.SetAnimationSpecifies an Audio-Video Interleaved (AVI) clip that runs in the dialog box.SetCancelMsgSets a message to be displayed if the user cancels the operation.SetLineDisplays a message.SetProgressUpdates the progress dialog box with the current state of the operation.SetProgress64Updates the progress dialog box with the current state of the operation.SetTitleSets the title of the progress dialog box.StartProgressDialogStarts the progress dialog box.StopProgressDialogStops the progress dialog box and removes it from the screen.TimerResets the progress dialog box timer to zero.
具体用法请参照MSDN,参照下面源代码就可以明白其用法,WIN7+Delphi XE3 调试通过。
以下为主要代码片断,主要步骤为:
1. 通过CreateComObject创建COM对象得到IProgressDialog接口
2. SetTitle设置标题,SetLine设置各行显示文本(可设置的有三行,行号从1开始)
3. StartProgressDialog显示对话框
4. 在任务执行过程中调用SetProgress设置进度条(通过HasUserCancelled检测是否用户取消)
5. StopProgressDialog关闭对话框,释放接口
procedure TFormMain.btnStartClick(Sender: TObject);var pNil: Pointer; I: Integer;begin ProgressDialog := CreateComObject(CLSID_ProgressDialog) as IProgressDialog; ProgressDialog.SetTitle(PWideChar(Caption)); ProgressDialog.SetProgress(0, max); ProgressDialog.SetLine(1, PWideChar(Format('进行%d次循环', [max])), True, pNil); ProgressDialog.StartProgressDialog(Handle, nil, PROGDLG_AUTOTIME or PROGDLG_NOMINIMIZE, pNil); for I := 0 to max do begin if ProgressDialog.HasUserCancelled then begin Break; end; ProgressDialog.SetProgress(I, max); ProgressDialog.SetLine(2, PWideChar(Format('当前循环到:%d', [I])), True, pNil); Application.ProcessMessages; end; ProgressDialog.StopProgressDialog; ProgressDialog := nil;end;
要进行时间自动估算,使用PROGDLG_AUTOTIME标志,并且时间会自动显示在Line3,所以SetLine设置文本时,不要使用第3行.
源代码下载:http://www.ctdisk.com/file/11965303
- Delphi调用IProgressDialog接口示例
- delphi调用https接口
- delphi中调用tuxedo示例
- Delphi调用DLL中的接口
- Delphi调用DLL中的接口
- Delphi调用Http接口方法
- OPS调用RTDB接口示例
- 使用CURL调用接口[*示例*]
- ajax 调用后台接口示例
- rmi远程接口调用示例
- Delphi调用Windows打开方式对话框示例
- DELPHI 调用SAP—RFC 示例
- Delphi XE8 百度 JavaScript API 调用示例
- 汉王扫描仪调用接口,delphi代码
- delphi调用java编写的http接口
- C#调用delphi dll接口问题
- Delphi调用Http接口上传文件
- C#调用Delphi接口(ITest = interface)
- 点、线、面相关的算法(1)
- 当浏览器从 web 服务器请求服务时,可能会发生错误。从而有可能会返回下面的一系列状态 错误消息汇总
- Eclipse快捷键大全(转载)
- linux 下 vim 操作
- libvirt学习
- Delphi调用IProgressDialog接口示例
- 堆与栈有什么区别?
- 计算机语言
- python读取文件:固定大小内容
- 点、线、面相关的算法(2)
- 《一步一脚印 90后程序员》18
- windows 核心编程中的通过消息发送数据
- Oracle 10g 下载
- Libvirt介绍