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

gold_future 2005-08-08 10:08:36
以下为我的代码:
function GetCaretScreenPos() : TPoint;
var
aHandle : THandle;
aThread : THandle;
aFocus : THandle;
aFocusRect : TRect;
aCaretPos : TPoint;
i : Integer;
aRes : LongBool;
begin
aHandle := GetForegroundWindow();
aThread:=GetWindowThreadProcessId(aHandle);
AttachThreadInput(GetCurrentThreadId,AThread,True);
SetActiveWindow(aHandle);
aFocus := GetFocus;
GetCaretPos(aCaretPos) then
windows.ClientToScreen(aFocus, aCaretPos);
AttachThreadInput(GetCurrentThreadId,AThread,False);

Result.X := aCaretPos.X;
Result.Y := aCaretPos.Y;
end;

在其它所有窗口(edit combobox, richedit)中都可以, 只有 Word 中不可用不知为什么,
我不想用VBA 来实现.
...全文
177 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
konhon 2005-08-25
  • 打赏
  • 举报
回复
// 获得当前窗口上闪烁光标的屏幕坐标
// 两个win32 api函数(见于msdn)
// GetCaretPos 用于获得光标 相对于客户区的 坐标
// ClientToScreen 用于将客户区 坐标 转换为 屏幕坐标

var
CurPoint:TPoint;
begin
GetCaretPos(CurPoint);
label1.Caption :=inttostr(clienttoscreen(CurPoint).X)+':'+inttostr(clienttoscreen (CurPoint).Y);
end;
naughtyboy 2005-08-10
  • 打赏
  • 举报
回复
gz
机子上没有装word
明天到公司看看

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧