Delphi调用IProgressDialog接口示例
2012-11-21 14:58
519 查看
IProgressDialog是Windows外壳提供的用于显示进度的对话框,包含文本提示及进度条,还可自动进行时间估算。
该接口主要包含以下方法:
具体用法请参照MSDN,参照下面源代码就可以明白其用法,WIN7+Delphi XE3 调试通过。
以下为主要代码片断,主要步骤为:
1. 通过CreateComObject创建COM对象得到IProgressDialog接口
2. SetTitle设置标题,SetLine设置各行显示文本(可设置的有三行,行号从1开始)
3. StartProgressDialog显示对话框
4. 在任务执行过程中调用SetProgress设置进度条(通过HasUserCancelled检测是否用户取消)
5. StopProgressDialog关闭对话框,释放接口
要进行时间自动估算,使用PROGDLG_AUTOTIME标志,并且时间会自动显示在Line3,所以SetLine设置文本时,不要使用第3行.
源代码下载:http://www.ctdisk.com/file/11965303
该接口主要包含以下方法:
HasUserCancelled | Checks whether the user has canceled the operation. |
SetAnimation | Specifies an Audio-Video Interleaved (AVI) clip that runs in the dialog box. |
SetCancelMsg | Sets a message to be displayed if the user cancels the operation. |
SetLine | Displays a message. |
SetProgress | Updates the progress dialog box with the current state of the operation. |
SetProgress64 | Updates the progress dialog box with the current state of the operation. |
SetTitle | Sets the title of the progress dialog box. |
StartProgressDialog | Starts the progress dialog box. |
StopProgressDialog | Stops the progress dialog box and removes it from the screen. |
Timer | Resets the progress dialog box timer to zero. |
以下为主要代码片断,主要步骤为:
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
相关文章推荐
- 《GOF设计模式》—组合(COMPOSITE)—Delphi源码示例:组合接口
- Delphi调用Http接口上传文件
- 《GOF设计模式》—装饰(DECORATOR)—Delphi源码示例:装饰接口
- 《GOF设计模式》—代理(PROXY)—Delphi源码示例:代理接口
- 中科院中文分词C语言接口调用示例
- PopWindow使用,,OpinionFeedbackActivity,MyPopWindow,MyProgressDialog,PhotoGridViewAdapter,调用系统的拍照和相册
- 使用Delphi调用WebServices接口的简单应用实例
- windows Azure 虚拟机接口调用示例
- 全国天气预报接口JAVA调用示例
- 《GOF设计模式》—原型(Prototype)—Delphi源码示例:原型接口
- Delphi通过调用Http接口实现短信发送的功能
- 《GOF设计模式》—原型(Prototype)—Delphi源码示例:原型接口
- 证件识别接口JAVA调用示例
- php调用google接口生成二维码示例
- Delphi调用DLL中的接口(转)(一个FreeLibrary时 报错的解决方案)
- 微信企业号开发之网页授权接口调用示例
- 《GOF设计模式》—状态(STATE)—Delphi源码示例:状态接口
- JNI 接口 简介 与 示例 java 调用 c++
- caffe预测、特征可视化python接口调用(caffe python接口调用示例)