API C# - 如何获取另一个程序中插入符号所在的文本框的句柄?

发布于 2024-10-05 05:25:51 字数 171 浏览 0 评论 0原文

我想在另一个程序中获取插入符号所在的文本框的句柄。我能找到的只是如何使用“EnumChildWindows”获取窗口中的控件列表,然后搜索“编辑”控件..(它不适用于所有具有文本框的程序)。 我不知道如何找到插入符所在的位置以及用户正在写入的位置。 我真的被困住了..:( 非常感谢, 施然。

i want to get the handle of the textbox where the caret is in, in another program. all i can find is how to get the list of the controls in a window with "EnumChildWindows", and then to search for "edit" control.. (and it doesn't work for all the program that have textbox).
i have no idea how to find the one that the caret is in and the user is writing in.
i really got stuck with it.. :(
thanx alot,
Shiran.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×纯※雪 2024-10-12 05:25:51

您需要跳过几个 pinvoke 圈。从 GetForegroundWindow() 开始获取活动顶层窗口的句柄。然后 GetThreadWindowProcessId() 获取拥有该窗口的线程的 ID。最后GetGUIThreadInfo(),它返回一堆关于线程拥有的窗口的信息。 GUITHREADINFO.hwndCaret 成员为您提供拥有插入符号的窗口的句柄。顺便说一句,它不一定是文本框。

请访问 pinvoke.net 获取您需要的声明。

You'll need to jump through several pinvoke hoops. Start with GetForegroundWindow() to get the handle of the active toplevel window. Then GetThreadWindowProcessId() to obtain the ID of the thread that owns that window. Then finally GetGUIThreadInfo(), it returns a bunch of into about the windows owned by the thread. The GUITHREADINFO.hwndCaret member gives you the handle to the window that owns the caret. It doesn't have to be a text box btw.

Visit pinvoke.net for the declarations you'll need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文