Just to make clear, this is the code I use to send the button click:
Private Declare Function SendMessageLong _
Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Long) As Long
Public Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202
Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private Const MK_LBUTTON As Long = &H1
Private Const MK_RBUTTON As Long = &H2
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, _
lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub ButtonClick(lHwnd As Long, _
Optional strClassName As String, _
Optional strWindowTitle As String, _
Optional bRightButton As Boolean)
Dim DaWord As Long
Dim lLeft As Long
Dim lTop As Long
Dim lRight As Long
Dim lBottom As Long
If Len(strClassName) > 0 Then
lHwnd = FindWindow(strClassName, strWindowTitle)
End If
GetWindowCoordinates lHwnd, lLeft, lTop, lRight, lBottom
'Centers the click and 15 is twips per pixel
DaWord = MakeDWord(((lRight - lLeft) / 15) / 2, ((lBottom - lTop) / 15) / 2)
If bRightButton Then
'this doesn't work
SendMessageLong lHwnd, WM_RBUTTONDOWN, MK_RBUTTON, ByVal DaWord
SendMessageLong lHwnd, WM_RBUTTONUP, MK_RBUTTON, ByVal DaWord
Else
SendMessageLong lHwnd, WM_LBUTTONDOWN, MK_LBUTTON, ByVal DaWord
SendMessageLong lHwnd, WM_LBUTTONUP, MK_LBUTTON, ByVal DaWord
End If
End Sub
Private Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
Sub GetWindowCoordinates(lHwnd As Long, _
lLeft As Long, lTop As Long, _
lRight As Long, lBottom As Long)
Dim RC As RECT
GetWindowRect lHwnd, RC
lLeft = RC.Left
lTop = RC.Top
lRight = RC.Right
lBottom = RC.Bottom
End Sub
Note that I can't do the right-click, even if I supply the x and y coordinates.
RBS