How to enumerate all windows within a process?

前端 未结 4 1553
日久生厌
日久生厌 2020-12-06 18:44

I need to capture particular windows of 3rd party process. I can find main window handle as Process.MainWindowHandle, but what I can use to list other windows?

I am

相关标签:
4条回答
  • 2020-12-06 19:15

    3rd party aplication launched other windows not as child windows.

    It is possible to find out what is structure using Spy++ tool which comes with Visual Studio.

    After this, I was able to find necessary window using FindWindowEx function using WindowClassName (taken from Spy++): lastWindows = FindWindowEx(IntPtr.Zero, lastWindows, m.WindowClassName, null);

    0 讨论(0)
  • 2020-12-06 19:22

    Use the Win32 API EnumWindows (and if you want EnumChildWindows)

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

    Then check which process each window belongs to by using the Win32 API GetWindowThreadProcessId

    [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
    public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);
    
    0 讨论(0)
  • 2020-12-06 19:28

    .NET (C#): Getting child windows when you only have a process handle or PID?

    0 讨论(0)
  • 2020-12-06 19:40

    The EnumChildWindows function might help you out. The child windows could also have children and so on.

    There is also GetWindow and EnumThreadWindows

    Another post here with some more details: Get handles to all windows of a process

    0 讨论(0)
提交回复
热议问题