模拟Lotus-Notes,VBA中的单击按钮

时间:2013-01-02 23:01:43

标签: vba lotus-notes

我在Lotus-Notes中有一个应用程序。我没有开发者权限。我的主要目标是自动化一些过程。为此,我需要知道如何模拟在Lotus-Notes应用程序中单击视图中的按钮。我在VBA开发它。

我的切入点是使用NotesUIWorkspace的OpenDatabase方法打开视图:

Call notesUIWorkspace.OpenDatabase( server$, file$, view$, key$, newInstance, temp )

现在,当视图打开时,我想模拟单击其上的按钮。非常感谢您的帮助。

BTW我不想直接从数据库插入/读取文档。我需要按原样完成所有过程。

4 个答案:

答案 0 :(得分:1)

我相信你可能会遇到这种方法遇到的许多障碍。没有COM方法来模拟Notes中的按钮单击。您可能能够获得NotesUIDocument的句柄,然后运行Save操作等,但如果您的按钮不止于此,那将无济于事。

我会查看AutoHotKey。它是Windows键盘和鼠标自动化工具。您可以编写一个脚本来自动执行所有操作,可能只是使用键盘快捷键。

答案 1 :(得分:0)

在该按钮中,您想要执行什么?

通常,您无法以编程方式单击“备注”操作。您可以在Queryopen中为所有视图编写代码。

否则你可以创建自定义工具栏操作,在那里你可以创建和计算@Formula。

http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.notes85.help.doc/fram_customize_toolbars_t.html

答案 2 :(得分:0)

为什么不能简单地将代码从按钮移动到库并调用函数而不是单击按钮?

答案 3 :(得分:0)

无法通过COM,您可以通过Winapi发送消息功能。下面的东西会起作用,虽然它非常笨重。我在一些自动化项目中使用它来模拟点击笔记按钮。

   Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long

' GetWindow() Constants
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3
Public Const GW_OWNER = 4
Public Const GW_CHILD = 5
Public Const GW_MAX = 5

'button click constants for SendMessage
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const BM_SETSTATE = &HF3
Public Const BM_GETSTATE = &HF2
Public Const BM_CLICK = &HF5

Public hwndAction As String
Public hwndClass As String
Public hwndCaption As String
Public hwndHandle As Long

Sub ClickNotes()

hwndAction = "FindHandle"
hwndCaption = "WindowCaption" ''Window Caption here
hwndClass = "NotesSubprog"


FindChildWindows(FindWindow("SWT_Window0", "Windowtitle"))

hwndAction = "FindHandle"
hwndCaption = "WindowCaption"
hwndClass = "NotesSubprog"

FindChildWindows(hwndHandle)


hwndAction = "FindHandle"
hwndCaption = ""
hwndClass = "ActionBar"

FindChildWindows(hwndHandle)

hwndAction = "Click"
hwndCaption = "Comment"
hwndClass = "IRIS.bmpbutton"

FindChildWindows(hwndHandle)

Do While FindWindow("SWT_Window0","New Comment - IBM Notes") = 0
DoEvents
Loop

Wait 3


End Sub

'the method signature is like this only to stay compatible with the Win32 API - lParam will not be used anyway
Function EnumChildWindow(ByVal hChild As Long, ByVal lParam As Long) As Long

Dim ClassBuffer As String
Dim CaptionBuffer As String
Dim TempVar As Long

ClassBuffer = Space(150)
TempVar = GetClassName(hChild, ClassBuffer, 149)
ClassBuffer = Left(ClassBuffer, TempVar)

CaptionBuffer = Space(250)
TempVar = GetWindowText(hChild, CaptionBuffer, 250)

CaptionBuffer = Left(CaptionBuffer, TempVar)

Debug.Print "Handle: " & hChild & ", Class: " & ClassBuffer & ", Caption: " & CaptionBuffer

If hwndClass = ClassBuffer And hwndCaption = CaptionBuffer Then
Select Case hwndAction
Case "Click"
SendMessage(hChild, WM_LBUTTONDOWN, 0, 0)
SendMessage(hChild, WM_LBUTTONUP, 0, 0)
SendMessage(hChild, BM_SETSTATE, 1, 0)
Case "FindHandle"
hwndHandle = hChild
End Select

Exit Function

End If

'Continue enumeration by recursion
EnumChildWindow = True

End Function

Function FindChildWindows(ByVal hParent As Long)

Dim hChild As Long
Dim Continue As Boolean

Continue = True
hChild = GetWindow(hParent, GW_CHILD)
Continue = EnumChildWindow(hParent, 0)

While Not hChild = 0 And Continue

If Continue Then Continue = FindChildWindows(hChild)
hChild = GetWindow(hChild, GW_HWNDNEXT)

Wend

FindChildWindows = Continue

End Function