verasen
asked on
Get screen coordinates of cursor in MS Word
I need to get the x,y screen pixel coordinates of the cursor (also known as Caret) in MS Word. Anyone know how?
What exactly are you trying to do, just get the screen co ordinates on a userform from VBA or are you trying to select a word that is underneath the mouse cursor or what ?
Apparently s/he just wants to get the Point location of the Caret (the blinky thing when you type)... I don't do VB myself.. but I'm not too sure if you can actually get the screen co-ordinates with an existing API.. What I would personally do, is get the Caret position, in the Text Box, then determine it's position (based on the font size) relative to the top-left corner of the Text Field... once you've got that, you can then add it on to the position of the Text Box (in terms of screen dimensions)..
I don't do VB as I've said, so there *might* be a really easy way.. but in one of my languages, that's how I'd probably do it.
>> IM
I don't do VB as I've said, so there *might* be a really easy way.. but in one of my languages, that's how I'd probably do it.
>> IM
Use the GetCursorPos() API:
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Command1_Click()
Dim Point As POINTAPI
GetCursorPos Point
Debug.Print Point.x & ", " & Point.y
End Sub
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Command1_Click()
Dim Point As POINTAPI
GetCursorPos Point
Debug.Print Point.x & ", " & Point.y
End Sub
ASKER
GetCursorPos tells mouse location. I need caret location (blinking thing) in MS Word
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.