将文本插入到另一个应用程序的文本框中 [英] Insert text into the textbox of another application

查看:222
本文介绍了将文本插入到另一个应用程序的文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用C#或C ++,将文本插入到另一个应用程序的文本框中?
我这样做很久以前,似乎记住了一些关于使用应用程序HWND。但是,从应用程序的每个实例的变化,我觉得我不记得完整的故事。我以某种方式得到一个正在运行的应用程序列表,提取一个我想要的,从那里得到HWND然后... hmm ....然后什么? :)

How do I, using C# or C++, insert text into the textbox of another application? I did this a long time ago and seemed to remember something about using the applications HWND. But since that change for every instance of the application I feel that I fon't remember the complete story. Do I somehow get a list of running apps, extract the one I want, get the HWND from that and then... hmm.... then what? :)

推荐答案

使用 FindWindowEx()找到句柄(HWND),然后发送WM_SETTEXT 消息,使用 SendMessage()

Use FindWindowEx() to find the handle (HWND) and then send the WM_SETTEXT message using SendMessage()

当使用FindWindowEx时,您需要首先使用它的类名来找到主窗口句柄。然后,您将需要找到文本框所在的任何容器的句柄,调用FindWindowEx,传递父(窗口)的句柄和容器的类名。您需要重复此操作,直到到达文本框。您可以使用默认情况下安装的名为 Spy ++ 的工具使用Visual Studio检查目标应用程序,并找到容器的层次结构(所有对象在API中真正称为窗口,但我调用它们的容器与顶层窗口相反)和它们的类名。

When using FindWindowEx you will need to first find the main window handle by using its class name. Then you will need to find the handle of whatever container the textbox is in, calling FindWindowEx, passing the handle of the parent (the window), and the class name of the container. You will need to repeat this until you reach the textbox. You can use a tool called Spy++ that is installed by default with Visual Studio to inspect the target application and find out the hierarchy of containers (all objects are really called windows in the API but I'm calling them containers in contrast with the top-level window) with their class names.

这篇关于将文本插入到另一个应用程序的文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆