2013-01-02 27 views
1

我在Lotus-Notes中有一個應用程序。我沒有開發者權利。我的主要目標是自動化一些過程。爲此,我需要知道如何模擬在Lotus-Notes應用程序中單擊視圖中的按鈕。我在VBA中開發它。模擬Lotus-Notes中的單擊按鈕,VBA

我的切入點是打開使用NotesUIWorkspace的OpenDatabase方法的觀點:

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

現在當視圖打開我想模擬點擊一個按鈕,是就可以了。非常感謝你的幫助。

順便說一句我不想直接從數據庫中插入/讀取文檔。我需要經歷所有的過程。

+0

你究竟想要做什麼? '我需要完成所有流程'是什麼意思? 如果您試圖使用VBA模仿Notes應用程序中的代碼,您需要有人與您共享該代碼,以便您可以在VBA中重寫該代碼,或者您將不得不通過試用反向設計代碼,錯誤。不知道「過程」是什麼,很難提供任何好的幫助。 – user1918954

回答

1

我相信你會遇到一些這樣的路障。沒有COM方法來模擬Notes中的按鈕點擊。您可能能夠獲得NotesUIDocument的句柄,然後運行保存操作等,但如果您的按鈕做的不止這些,那也無濟於事。我想結賬AutoHotKey。它是一個Windows鍵盤和鼠標自動化工具。您可以編寫一個腳本來自動執行所有操作,可能只是使用鍵盤快捷鍵。

0

你爲什麼就不能簡單地從移動按鈕的代碼庫,並調用函數,而不是點擊按鈕?

+0

問題是我沒有訪問代碼的權限。我在該應用中的權限非常低。 – f1024

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