7

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 using C# / .NET

st78
  • 7,657
  • 11
  • 48
  • 64

4 Answers4

3

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

Community
  • 1
  • 1
Svetlozar Angelov
  • 20,444
  • 6
  • 61
  • 67
3

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

Community
  • 1
  • 1
Cory Charlton
  • 8,721
  • 4
  • 47
  • 66
3

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

st78
  • 7,657
  • 11
  • 48
  • 64
3

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);
Brian R. Bondy
  • 327,498
  • 120
  • 583
  • 623