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
  • 8,028
  • 11
  • 49
  • 68

4 Answers4

3

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

Community
  • 1
  • 1
Svetlozar Angelov
  • 21,214
  • 6
  • 62
  • 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,868
  • 4
  • 48
  • 68
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
  • 8,028
  • 11
  • 49
  • 68
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
  • 339,232
  • 124
  • 596
  • 636