Bridge Guy
New Member
- Joined
- Nov 9, 2023
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
I am developing an Excel add-in using VSTO in Visual Studio with VB.NET. I would like to capture the cursor position on the mouse in screen/ pixel coordinates. I downloaded the following subroutine that is written by others and posted on an Excel VBA forum. The subroutine uses the Windows API function GetCursorPos. The function returns Result and the X and Y coordinates of the declared IICoord structure as 0. The POINTAPI was declared as a Type in the original post and I have used the VB.NET structure here.
I have used a limited amount of Windows APIs in my VSTO projects before with good results. Any insight into what may cause the problem would be appreciated.
Thanks
Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long
Public Structure POINTAPI
Public X As Long
Public Y As Long
End Structure
Sub GetCursorPosDemo()
Dim llCoord As POINTAPI
Dim Result As Object
' Get the cursor positions
Result = GetCursorPos(llCoord)
' Display the cursor position coordinates
MsgBox("X Position: " & llCoord.X & vbNewLine & "Y Position: " & llCoord.Y)
End Sub
I have used a limited amount of Windows APIs in my VSTO projects before with good results. Any insight into what may cause the problem would be appreciated.
Thanks
Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long
Public Structure POINTAPI
Public X As Long
Public Y As Long
End Structure
Sub GetCursorPosDemo()
Dim llCoord As POINTAPI
Dim Result As Object
' Get the cursor positions
Result = GetCursorPos(llCoord)
' Display the cursor position coordinates
MsgBox("X Position: " & llCoord.X & vbNewLine & "Y Position: " & llCoord.Y)
End Sub