我用的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  这个方法错了呢?

解决方案 »

  1.   

    API上说GetWindowText不能跨进程,难道C#真的做不到?
      

  2.   

    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));
      

  3.   


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

  4.   

    我将 IntPtr ptr = Marshal.StringToHGlobalAnsi(w);改成了 IntPtr ptr = Marshal.StringToHGlobalAuto(w);然后好用了,可以找到全部字符了,但是不明白为什么...
      

  5.   

    其他的可以用GetWindowText来获取,文本框要用SendMessage来发送WM_GETTEXT消息来获取