没办法通过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