2

Using pinvoke I can find Handle of a window with particular class & name easily:

[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr hWnd = FindWindow("Foo Class", "Foo Window");

The above code works perfect if there is only 0 or 1 matching windows. However the unmanaged application I am working with spans multiple windows. Calling FindWindow multiple times returns the same Window Handle each time.

What do I need to do to get ALL windows with particular class and name.

I will also accept answer for alternate solution the same goal. (I am thinking maybe it can be done by finding process ID of application and then getting all top level windows, and filtering for the ones needed).

Gerald Davis
  • 4,541
  • 2
  • 31
  • 47
  • possible duplicate of [using FindWindow with multiple root windows](http://stackoverflow.com/questions/257879/using-findwindow-with-multiple-root-windows) – Cody Gray - on strike Jun 04 '11 at 14:25

1 Answers1

4

You probably need to call EnumWindows to enumerate ALL top-level windows. You'll have to use their window handles to get their titles and window class information.

See http://www.pinvoke.net/default.aspx/user32/enumwindows.html for an example that does very close to what you're asking.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • Thanks. I found at the link you provided a link to: http://mwinapi.sourceforge.net/ A managed wrapper for some of the user32 functions. Much nicer to work with then recoding the wheel with pinvokes. – Gerald Davis Jun 04 '11 at 19:17