C# 如何使用 WM_GETTEXT / GetWindowText API / 窗口标题
我想获取应用程序的控件/句柄的内容..
这是实验代码..
Process[] processes = Process.GetProcessesByName("Notepad");
foreach (Process p in processes)
{
StringBuilder sb = new StringBuilder();
IntPtr pFoundWindow = p.MainWindowHandle;
List <IntPtr> s = GetChildWindows(pFoundWindow);
// function that returns a
//list of handle from child component on a given application.
foreach (IntPtr test in s)
{
// Now I want something here that will return/show
the text on the notepad..
}
GetWindowText(pFoundWindow, sb,256);
MessageBox.Show(sb.ToString()); // this shows the title.. no problem with that
}
有什么想法吗? 我读过一些 API 方法,如 GetWindowText 或 WM_GETTEXT,但我不知道如何使用它或将其应用到我的代码中。 我需要教程或示例代码...
提前致谢:)
I want to get the content of the control / handle of an application..
Here's the experimental code..
Process[] processes = Process.GetProcessesByName("Notepad");
foreach (Process p in processes)
{
StringBuilder sb = new StringBuilder();
IntPtr pFoundWindow = p.MainWindowHandle;
List <IntPtr> s = GetChildWindows(pFoundWindow);
// function that returns a
//list of handle from child component on a given application.
foreach (IntPtr test in s)
{
// Now I want something here that will return/show
the text on the notepad..
}
GetWindowText(pFoundWindow, sb,256);
MessageBox.Show(sb.ToString()); // this shows the title.. no problem with that
}
any idea?
I've read some API method like GetWindowText or WM_GETTEXT but I dont know how to use it or apply it on my code..
I need a tutorial or sample code...
Thanks in advance : )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GetWindowText 不会为您提供其他应用程序的编辑窗口内容 -
您需要使用 SendMessage 的 StringBuilder 版本:
GetWindowText won't give you the content of edit windows from other applications - it only supports default-managed text [like the captions of labels] across processes to prevent hangs... you'll have to send WM_GETTEXT.
You'll need to use a StringBuilder version of SendMessage:
看看 http://pinvoke.net/default.aspx/user32/GetWindowText.html 以及 MSDN 上的文档。下面是如何使用 GetWindowText 方法的简短代码示例。
Have a look at http://pinvoke.net/default.aspx/user32/GetWindowText.html and also the documentation on MSDN. Below you find a short code example how to use the GetWindowText method.