0

When enumerating windows using EnumWindows, I get hundreds of handles instead of one per open window on my desktop.

First of all, i am curious if this is the correct behavior.

Secondly, trying to get a difference between open windows before and after launching a process returns 15-20 new handles. I am wondering if there is a way to filter these based on some flag, i really need just the mainwindow handle.

Any ideas?

Alex
  • 2,292
  • 1
  • 17
  • 29

2 Answers2

1

To get the main window of a process, use the Process.MainWindowHandle property.

To answer your question, you can see exactly what all of the handles are using Spy++.
In short, many applications will create hidden windows to run message loops.

SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933
  • 1
    +1, still, keep in mind that there's no such a thing as a "main window" for a process, IIRC MainWindowHandle just retrieves the first top-level visible window created by the application it can find. This usually isn't a big problem, but for application which create several top-level windows (e.g. Outlook) it may give incorrect results. – Matteo Italia Jun 04 '10 at 09:24
0

You can filter within the enum callback by checking IsWindowVisible() & ignoring invisible system/message sink windows.

Alex K.
  • 165,803
  • 30
  • 257
  • 277