PDA

View Full Version : 技巧:如何在Notes窗口中显示进度条


imzh
15-01-07, 03:23 PM
此代码我做了测试,成功!!
如何在程序中加入进度条?
-------------------------------------------
Option:
Option Public
声明部分(Declaration)
Declare Public Function NEMProgressBegin Lib "nnotesws.dll" ( Byval wFlags As Integer ) As Long
Declare Public Sub NEMProgressDeltaPos Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwIncrement As Long )
Declare Public Sub NEMProgressEnd Lib "nnotesws.dll" ( Byval hwnd As Long )
Declare Public Sub NEMProgressSetBarPos Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwPos As Long)
Declare Public Sub NEMProgressSetBarRange Lib "nnotesws.dll" ( Byval hwnd As Long, Byval dwMax As Long )
Declare Public Sub NEMProgressSetText Lib "nnotesws.dll" ( Byval hwnd As Long, Byval pcszLine1 As Lmbcs String, Byval pcszLine2 As Lmbcs String)
Const NPB_TWOLINE = 3
Const NPB_ONELINE = 2
Public Class LNProgressbar
hwnd As Long
Sub New(SecondLineVisible As Integer)
'Set-up the progress bar on the screen
If SecondLineVisible Then
hwnd = NEMProgressBegin(NPB_TWOLINE)
Else
hwnd = NEMProgressBegin(NPB_ONELINE)
End If
End Sub
Sub SetText(FirstLineText As String,SecondLineText As String)
'Display the text in progress bar
NemProgressSetText hwnd, FirstLineTExt,SecondLineText
End Sub
Sub SetProgressPos(Progresspos As Long)
NEMProgressSetBarPos hwnd, ProgressPos
End Sub
Sub SetProgressRange(ProgressMaxElements As Long)
'Set-up the max elements in the progress bar, if you have
'a list with 230 elements then set the MAX to 230 elements.
'For every element you proceed increase the SetProgressPos
'by one to reached 230
NEMProgressSetBarRange hwnd, ProgressMaxElements
End Sub
Sub DeltaPos(DPos As Long)
' This function adds the number in DPOS to the current ProgressPos
NEMProgressDeltaPos hwnd, DPos
End Sub
Sub Delete
'Terminate the progress bar on the screen
NEMProgressEnd hwnd
End Sub
End Class
操作按钮的Click事件:
Sub Click(Source As Button)
Dim pb As New LNProgressBar(True)
Dim i As Long
Call pb.SetText("这是一个测试","来自http://www.flycat.net")
'set the range to 10000 elements
Call pb.SetProgressRange(10000)
For i=1 To 10000
' process the elements
Call pb.SetProgressPos(i)
Next
'Terminate the progress bar
Delete pb
End Sub

imzh
15-01-07, 03:27 PM
此文章未经测试,但描述比较详细,所以也贴上来。

在Notes 的C/S 编程中,经常需要对一个集合中的对象进行遍历处理,这时如果能显示一个进度条指示当前处理进程,就比较直观形象,客户界面也比较友好。但是Notes中没有提供相关的信息。于是我们不得不调用未经公开的API函数。
以下LotusScript代码在 5.07 以后版本中测试通过,5.07以前的版本未测试。


1、首先是自定义一个类 ProgressBar 。这样以后的调用比较方便。

'声明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 )

'定义 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
'类结束

2、如何调用
在任意过程或者函数中,都可以用 new ProgressBar 调用。在调用时,需要先声明一个常量 NPB_TWOLINE% ,当NPB_TWOLINE%=1 时,显示的是位于窗口中间偏上的较大的进度条,当NPB_TWOLINE%=32 时,显示的是位于屏幕下方的小进度条。

例子:
把ProgressBar 类代码写在数据库资源的 Database Script 中,并命名为 ProgressBar。

在某个过程的(Options)中:
Use "ProgressBar"

在过程代码中:

Sub Initialize
Const NPB_TWOLINE% = 1
dim pb as new ProgressBar(10000)
dim i as long
for i=1 to 10000
'....
call pb.UpdatePosition(i)
next i
End Sub


3、实际上,Notes中有许多有用的API函数,有兴趣的可以用某些对象浏览器分析一下Notes 中的.dll 类库。

hzjman1999
15-01-07, 03:37 PM
顶了 慢慢看~~~~~~~~~~~~~~~~~~`

tobyzhou
15-01-07, 03:40 PM
牛人......PF