API C# - 如何获取另一个程序中插入符号所在的文本框的句柄?
我想在另一个程序中获取插入符号所在的文本框的句柄。我能找到的只是如何使用“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要跳过几个 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.