GetCaretPos can't get the correct value

W

wak

When i call GetCaretPos in MS Word Addin, It always return's a same value.
When i Enable IME,it can return the correct value. Some one can tell me why?
 
J

Jean-Guy Marcil

wak said:
When i call GetCaretPos in MS Word Addin, It always return's a same value.
When i Enable IME,it can return the correct value. Some one can tell me why?

What is "GetCaretPos?"

Many methods that work with the selection object will not work correctly (or
not at all) if the active window is not visible.
 
W

wak

Jean-Guy Marcil said:
What is "GetCaretPos?"

Many methods that work with the selection object will not work correctly (or
not at all) if the active window is not visible.

GetCaretPos is Win32Api, I think i can use API to do some tasks instead VBA.
I want to get the current caret postion.
 
H

Helmut Weber

Hi,

at work, with Office 2002 and Windows XP
I see the same behaviour as you do.

However, at home, with Vista Small Business
and Office XP, the following code is working:

Option Explicit
' ---------------------------------------------
Public Declare Function GetCaretPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Type POINTAPI ' 8 Bytes
x As Long
y As Long
End Type

Public Sub WhereAmI()
Dim p As POINTAPI
Dim l As Long
l = GetCaretPos(p)
ActiveDocument.Range.InsertAfter _
"(" & p.x & "," & p.y & ")"
MyStart
End Sub

Sub MyStart() ' for ongoing evaluation of caret position
Application.OnTime _
When:=Now + TimeValue("00:00:03"), _
name:="WhereamI"
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
W

wak

Helmut Weber said:
Hi,

at work, with Office 2002 and Windows XP
I see the same behaviour as you do.

However, at home, with Vista Small Business
and Office XP, the following code is working:

Option Explicit
' ---------------------------------------------
Public Declare Function GetCaretPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Type POINTAPI ' 8 Bytes
x As Long
y As Long
End Type

Public Sub WhereAmI()
Dim p As POINTAPI
Dim l As Long
l = GetCaretPos(p)
ActiveDocument.Range.InsertAfter _
"(" & p.x & "," & p.y & ")"
MyStart
End Sub

Sub MyStart() ' for ongoing evaluation of caret position
Application.OnTime _
When:=Now + TimeValue("00:00:03"), _
name:="WhereamI"
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Thanks for your code, it realy work.
but I want to know a common way to get
the caret pos of all versions of word,
and outlook have the same problem,
(GetCaretPos works ok in powerpoint).
Microsoft knows the caret pos, so i believe
there is a way to get it correct, any idea?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top