【问题标题】:How to enumerate all windows within a process?如何枚举进程中的所有窗口?
【发布时间】:2010-02-17 14:30:13
【问题描述】:

我需要捕获第 3 方进程的特定窗口。我可以找到主窗口句柄为 Process.MainWindowHandle,但我可以用什么来列出其他窗口?

我正在使用 C#/.NET

【问题讨论】:

    标签: c# windows process


    【解决方案1】:
    【解决方案2】:

    EnumChildWindows 函数可能会对您有所帮助。子窗口也可以有子窗口等等。

    还有GetWindowEnumThreadWindows

    另一个帖子在这里有更多细节:Get handles to all windows of a process

    【讨论】:

    • 感谢这个名字 - 我会在问题解决时关闭问题
    【解决方案3】:

    第 3 方应用程序启动了其他窗口而不是子窗口。

    可以使用 Visual Studio 自带的 Spy++ 工具找出什么是结构。

    在此之后,我能够使用 WindowClassName(取自 Spy++)使用 FindWindowEx 函数找到必要的窗口: lastWindows = FindWindowEx(IntPtr.Zero, lastWindows, m.WindowClassName, null);

    【讨论】:

      【解决方案4】:

      使用 Win32 API EnumWindows(如果你想要 EnumChildWindows

      [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
      public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
      

      然后通过Win32 APIGetWindowThreadProcessId检查每个窗口属于哪个进程

      [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
      public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);
      

      【讨论】:

        猜你喜欢
        • 2011-02-01
        • 2015-10-29
        • 2013-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-14
        相关资源
        最近更新 更多