如何从另一个程序的文本框中读取值

mfc198666_002 2011-02-18 01:16:50
我用的WIN32的API 如下:
IntPtr xx = FindWindow("WindowsForms10.Window.8.app.0.b7ab7b", "Form1");
if (xx != IntPtr.Zero)
{
byte[] buByte = new byte[1024];
int count = 0;
IntPtr cxx = FindWindowEx(xx, IntPtr.Zero, "WindowsForms10.EDIT.app.0.b7ab7b", null);
count = GetWindowText(cxx, buByte, 1024);
MessageBox.Show(Encoding.UTF8.GetString(buByte));
}

可以找到我自己做的程序的文本框值,但是别人的却找不到
是不是 GetWindowText 这个方法错了呢?
...全文
193 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
None465465535 2011-02-21
  • 打赏
  • 举报
回复
其他的可以用GetWindowText来获取,文本框要用SendMessage来发送WM_GETTEXT消息来获取
mfc198666_002 2011-02-21
  • 打赏
  • 举报
回复
我将 IntPtr ptr = Marshal.StringToHGlobalAnsi(w);

改成了 IntPtr ptr = Marshal.StringToHGlobalAuto(w);

然后好用了,可以找到全部字符了,但是不明白为什么...
mfc198666_002 2011-02-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyq11 的回复:]
int hEdit = FindWindowEx(p.MainWindowHandle, 0, "Edit", "");
string w = " ";
IntPtr ptr = Marshal.StringToHGlobalAnsi(w);
if (SendMessage(hEdit, WM_GETTEXT, 100, ptr))

Console.WriteLine(……
[/Quote]

谢谢你的回复,现在已经找到文本了,只差一点了:什么我找到文本不全,只有前几个字符?
还有 SendMessage(hEdit, WM_GETTEXT, 100, ptr) 这个 100 参数是干什么的啊?

谢谢
wuyq11 2011-02-18
  • 打赏
  • 举报
回复
int hEdit = FindWindowEx(p.MainWindowHandle, 0, "Edit", "");
string w = " ";
IntPtr ptr = Marshal.StringToHGlobalAnsi(w);
if (SendMessage(hEdit, WM_GETTEXT, 100, ptr))

Console.WriteLine(Marshal.PtrToStringAnsi(ptr));



mfc198666_002 2011-02-18
  • 打赏
  • 举报
回复
API上说GetWindowText不能跨进程,难道C#真的做不到?

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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