无法读取子窗口内容c#

时间:2012-11-27 16:19:15

标签: c# winforms

我正在使用此代码从软件中读取数据。

    [DllImport("user32", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
    public static extern IntPtr GetWindow(IntPtr hwnd, int wCmd);
    [DllImport("user32", EntryPoint="SendMessageA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
    public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
    [DllImport("user32", EntryPoint="SendMessageA", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
    public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, StringBuilder lParam);


        try
        {
            IEnumerator enumerator;
            MainModule.StrData = "";
            try
            {
                enumerator = this.chkListbox_1.CheckedIndices.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    object objectValue = enumerator.Current;
                    this.WindowText(this.chldwnds[Conversions.ToInteger(objectValue)]);
                }
            }
            finally
            {

            }
            Clipboard.Clear();
        }
        catch (Exception exception1)
        {

        }

  public object WindowText(IntPtr hWnd)
    {
        object obj2 = "";
        /////for the second window that is not black in color the hWnd value is 0.
        //but for the black one its giving some value in 10000's
        if (hWnd.Equals(IntPtr.Zero))
        {
            return "";
        }
        MainModule.SendMessage(hWnd, 0x111, (IntPtr)0x81eb, IntPtr.Zero);
        MainModule.StrData = MainModule.StrData + Clipboard.GetText();
        MainModule.SendMessage(hWnd, 0x307, IntPtr.Zero, IntPtr.Zero);
        return obj2;
    }

此图片中有2个窗口。 我能够读取黑色窗口但无法读取另一个窗口。 enter image description here

0 个答案:

没有答案