views:

318

answers:

4

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

+4  A: 

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: http://stackoverflow.com/questions/2238609/c-get-handles-to-all-windows-of-a-process

Cory Charlton
Thanks for this name - I will close question when problem will be solved
Sergey Osypchuk
A: 

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

Sergey Osypchuk
+1  A: 

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