How to Determine Text Cursor Position in Windows

2019-04-25 06:14发布

What is the best way to determine the screen co-ordinates of the currently active text input cursor?

I need this for an in-line transliteration program so that I can display some suggestions options to the user as the text is entered.

标签: winapi ime
1条回答
Ridiculous、
2楼-- · 2019-04-25 06:37

First attach the thread input to the active application (AttachThreadInput). Then get the caret's position with GetCaretPos. The position is in client coordinates, call GetFocus to have the handle to the window that has the caret, then convert the coordinates to screen coordinates with ClientToScreen. Finally detach the thread input by calling again AttachThreadInput.

查看更多
登录 后发表回答