I'm not sure if anyone cares but for completenesses sake I thought I'd post the answer to my earlier query.
It looks like the IDisplayServices interface can't be accessed when scipting with VBA - you have to be using C / C++. There were sevral more obstacles to getting this done but in answer to my specific query I needed to use the getBoundingClientRect mthod on the HTMLInputElement.
Below is some sample code which demonstrates the desired method by opening an internet explorer window, navigating to Google, putting something in the search box, finding the location of the search button, moving the move over the button & simulating a mouse click.
To get the code running in a VBA project you'll need to add references to Microsoft HTML Object Library (MSHTML) & Microsoft Internet Controls (SHDocVW).
Anyway, enjoy ...
Code:
Option Explicit
Private Type myRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Enum CoordType
Absolute
Pixels
End Enum
' User32 API functions used to determine screen resolution
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, rectangle As myRECT) As Long
' User32 API Mouse functions
Private Declare Sub mouse_event Lib "User32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
' Mouse Event Flags
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Sub Test()
Dim IExp As SHDocVw.InternetExplorer
Dim hDoc As MSHTML.HTMLDocument
Dim hCol As MSHTML.IHTMLElementCollection
Dim hInp As MSHTML.HTMLInputElement
Dim hPoint As MSHTML.tagPOINT
Set IExp = New SHDocVw.InternetExplorer
IExp.Visible = True
IExp.navigate "http://www.google.co.uk"
Do Until IExp.Busy = False
DoEvents
Loop
Set hDoc = IExp.document
' Find the "search for" input box on the page
Set hCol = hDoc.getElementsByTagName("input")
For Each hInp In hCol
If hInp.Name = "q" Then
hInp.Value = "Test" ' Put in something to look for
Exit For
End If
Next hInp
' Find the search button on the page
Set hCol = hDoc.getElementsByTagName("input")
For Each hInp In hCol
If hInp.DefaultValue = "Google Search" Then
' Scroll IE to top left hand corner
hDoc.parentWindow.scroll 0, 0
' Get coordinate of button
hPoint = GetCoord(hDoc, hInp, Absolute)
' Move mouse
mouse_event MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE, hPoint.X, hPoint.Y, 0, 0
' Simulate click
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Exit For
End If
Next hInp
End Sub
Private Function GetCoord(hDoc As MSHTML.HTMLDocument, hEle As MSHTML.HTMLInputElement, Output As CoordType) As MSHTML.tagPOINT
Dim ScreenRes As MSHTML.tagPOINT
Dim hIRectEle As MSHTML.IHTMLRect
Dim Point As MSHTML.tagPOINT
' Get the screen resolution
ScreenRes = GetScreenResolution
Set hIRectEle = hEle.getBoundingClientRect
' Find middle of input element
Point.X = (hIRectEle.Left + hIRectEle.Right) / 2
Point.Y = (hIRectEle.Top + hIRectEle.Bottom) / 2
' Add in offset for where the internet explorer window is located on screen
Point.X = Point.X + hDoc.parentWindow.screenLeft
Point.Y = Point.Y + hDoc.parentWindow.screenTop
' Convert to absolute coords, if necessary
If Output = Absolute Then
Point.X = (Point.X / ScreenRes.X) * 65000
Point.Y = (Point.Y / ScreenRes.Y) * 65000
End If
GetCoord = Point
End Function
Function GetScreenResolution() As MSHTML.tagPOINT
Dim R As myRECT
Dim hWnd As Long
Dim RetVal As Long
' Win API calls
hWnd = GetDesktopWindow()
RetVal = GetWindowRect(hWnd, R)
GetScreenResolution.X = (R.Right - R.Left)
GetScreenResolution.Y = (R.Bottom - R.Top)
End Function