输入法相关,如何定位光标(caret)的屏幕坐标, 我的方法在word 中不行,为什么 ( 积分: 90 )

  • 主题发起人 主题发起人 golden_future
  • 开始时间 开始时间
G

golden_future

Unregistered / Unconfirmed
GUEST, unregistred user!
以下为我的代码:<br>function &nbsp;GetCaretScreenPos() : TPoint;<br>var<br> &nbsp; &nbsp;aHandle : THandle;<br> &nbsp; &nbsp;aThread : THandle;<br> &nbsp; &nbsp;aFocus : THandle;<br> &nbsp; &nbsp;aFocusRect : TRect;<br> &nbsp; &nbsp;aCaretPos : TPoint;<br> &nbsp; &nbsp;i : Integer;<br> &nbsp; &nbsp;aRes &nbsp;: LongBool;<br>begin<br> &nbsp; &nbsp;aHandle := GetForegroundWindow();<br> &nbsp; &nbsp;aThread:=GetWindowThreadProcessId(aHandle);<br> &nbsp; &nbsp;AttachThreadInput(GetCurrentThreadId,AThread,True);<br> &nbsp; &nbsp;SetActiveWindow(aHandle);<br> &nbsp; &nbsp;aFocus := GetFocus;<br> &nbsp; &nbsp;GetCaretPos(aCaretPos) then<br> &nbsp; &nbsp;windows.ClientToScreen(aFocus, aCaretPos);<br> &nbsp; &nbsp;AttachThreadInput(GetCurrentThreadId,AThread,False);<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;Result.X := aCaretPos.X;<br> &nbsp; &nbsp;Result.Y := aCaretPos.Y;<br>end;<br><br>在其它所有窗口(edit combobox, richedit)中都可以, 只有 Word 中不可用不知为什么,<br>我不想用VBA 来实现.
 
以下为我的代码:<br>function &nbsp;GetCaretScreenPos() : TPoint;<br>var<br> &nbsp; &nbsp;aHandle : THandle;<br> &nbsp; &nbsp;aThread : THandle;<br> &nbsp; &nbsp;aFocus : THandle;<br> &nbsp; &nbsp;aFocusRect : TRect;<br> &nbsp; &nbsp;aCaretPos : TPoint;<br> &nbsp; &nbsp;i : Integer;<br> &nbsp; &nbsp;aRes &nbsp;: LongBool;<br>begin<br> &nbsp; &nbsp;aHandle := GetForegroundWindow();<br> &nbsp; &nbsp;aThread:=GetWindowThreadProcessId(aHandle);<br> &nbsp; &nbsp;AttachThreadInput(GetCurrentThreadId,AThread,True);<br> &nbsp; &nbsp;SetActiveWindow(aHandle);<br> &nbsp; &nbsp;aFocus := GetFocus;<br> &nbsp; &nbsp;GetCaretPos(aCaretPos) then<br> &nbsp; &nbsp;windows.ClientToScreen(aFocus, aCaretPos);<br> &nbsp; &nbsp;AttachThreadInput(GetCurrentThreadId,AThread,False);<br> &nbsp; &nbsp;<br> &nbsp; &nbsp;Result.X := aCaretPos.X;<br> &nbsp; &nbsp;Result.Y := aCaretPos.Y;<br>end;<br><br>在其它所有窗口(edit combobox, richedit)中都可以, 只有 Word 中不可用不知为什么,<br>我不想用VBA 来实现.
 
好多天了,还没有回答??
 
我也发现同样的问题,不过我还发现并不是不能发现,而是发现的时间滞后,大概滞后几秒
 
这个问题还没解决啊,很长时间了.....
 
试试 http://www.2ccc.com/article.asp?articleid=1794
 
刘麻子: <br><br>你的代码还是不行啊, 其它窗口都能取出来,就是 word 不能取出来, Excel 也是可以取出来的啊.<br><br>真不知道微软搞了什么鬼.....
 
后退
顶部