获取所有儿童窗口把手

时间:2017-02-04 06:08:26

标签: c# .net

我正在尝试获取在任务管理器的后台进程部分中运行的第三方应用程序的所有子窗口句柄。我尝试使用主窗口句柄,但是当应用程序作为后台进程运行时,它导致主窗口句柄为零。 任何人都可以帮我解决我的问题吗?

Process[] process = Process.GetProcessesByName("ipmsg");
        foreach (Process theprocess in process)
        {
            MessageBox.Show(theprocess.ProcessName);
        }
        IntPtr handle = process[0].MainWindowHandle;
        Process[] process1 = Process.GetProcessesByName("ipmsg");
        process1[0].WaitForInputIdle();
        IntPtr pt = process1[0].MainWindowHandle;
        MessageBox.Show(pt.ToString());
        string title = process[0].MainWindowTitle;

        StringBuilder className = new StringBuilder(200);
        int nret = GetClassName(handle, className, className.Capacity);
        IntPtr appHandle = handle;
        string caption1 = GetTextBoxText(appHandle);
        richTextBox1.AppendText(caption1 + " " + System.Environment.NewLine);
        richTextBox1.AppendText("App handle = " + appHandle.ToString("X"));
        List<string> children = GetAllChildrenWindowHandles(appHandle, 100);
        richTextBox1.AppendText("Children handles are:" + System.Environment.NewLine);
        for (int i = 0; i < children.Count; ++i)
        {
            Console.WriteLine(Convert.ToInt32(children[i]).ToString("X"));
            richTextBox1.AppendText(Convert.ToInt32(children[i]).ToString("X") + " " + System.Environment.NewLine);
            IntPtr appHandle_sub = new IntPtr(Convert.ToInt32(Convert.ToInt32(children[i]).ToString("X"), 16));
            string caption = GetTextBoxText(appHandle_sub);
            richTextBox1.AppendText(caption + " " + System.Environment.NewLine);
        }

0 个答案:

没有答案