在Notes 的C/S 编程中,经常需要对一个集合中的对象进行遍历处理,这时如果能显示一个进度条指示当前处理进程,就比较直观形象,客户界面也比较友好。
1、声明API函数
'声明API函数
Declare Function NEMProgressBegin Lib "nnotesws.dll"
( Byval wFlags As Integer ) As Long
Declare Sub NEMProgressEnd Lib "nnotesws.dll"
( Byval hwnd As Long )
Declare Sub NEMProgressSetBarPos Lib "nnotesws.dll"
( Byval hwnd As Long, Byval dwPos As Long)
Declare Sub NEMProgressSetBarRange Lib "nnotesws.dll"
( Byval hwnd As Long, Byval dwMax As Long )
Declare Sub NEMProgressSetText Lib "nnotesws.dll"
( Byval hwnd As Long, Byval pcszLine1 As String,
Byval pcszLine2 As String )
2、首先是自定义一个类 ProgressBar 。这样以后的调用比较方便。
'定义 ProgressBar 类
Class ProgressBar
Private hwnd As Long
' 构造类
Sub New (BarRange As Long)
On Error Goto ErrorHandler
' 创建进度条
Me.hwnd = NEMProgressBegin (NPB_TWOLINE)
' 设置进度条的总长
Call NEMProgressSetBarRange (Me.hwnd, BarRange)
Exit Sub
ErrorHandler:
Dim TheError As String
TheError = "Constructor: Error " + Str(Err) + ": " + Error$
Messagebox TheError, 0 + 48, "Progress Bar Error"
End Sub
' 回收对象
Public Sub Delete
' 取消进度条
Call NEMProgressEnd (Me.hwnd)
End Sub
Public Sub UpdatePosition (BarPos As Long)
' 公共方法:更新进度位置
Call NEMProgressSetBarPos (Me.hwnd, BarPos)
End Sub
Public Sub UpdateProgressText (BarMsg As String, UpdateMsg As String)
' 公共方法:更新进度条显示文字
Call NEMProgressSetText (Me.hwnd, BarMsg, UpdateMsg)
End Sub
End Class
'类结束
3、调用
在任意过程或者函数中,都可以用 new ProgressBar 调用。在调用时,需要先声明一个常量 NPB_TWOLINE% ,当NPB_TWOLINE%=1 时,显示的是位于窗口中间偏上的较大的进度条,当NPB_TWOLINE%=32 时,显示的是位于屏幕下方的小进度条。
例子:
把ProgressBar 类代码写在按钮的 Click Script 中,并命名为 ProgressBar。
在按钮的(Options)中:
Use "ProgressBar"
在按钮的Click中:
Sub Click
Const NPB_TWOLINE% = 1
dim pb as new ProgressBar(1000)
dim i as long
for i=1 to 1000
'....
call pb.UpdatePosition(i)
next i
End Sub