tags:

views:

388

answers:

3

I would like to end up with a list (or array or whatever) of all the visible (including minimised) windows.

I have found 2 similar questions, which don't quite give me what I'm looking for:
- Work out which windows go in the alt-tab list
- list windows in another user's session

Thanks.

+1  A: 

How about this to get a list of processes that would go into the alt-tab list. (Running processes that contain a window):

using System.Diagnostics.Process; 

List <Process()> plist = new List<Process>();            

foreach (Process p in Process.GetProcesses())
{
 string title = p.MainWindowTitle;
 if (!String.IsNullOrEmpty(title))
 {
     plist.Add(p);
 }
}
Rich
In theory you got it right, but there are two mistakes in your code. First your have a syntax error when creating the list:List<Process> plist = new List<Process>();Second, in your if statement, if you only check title for null, you get all processes. if (!String.IsNullOrEmpty(title)) works.
BFree
Thanks for noticing that - i fixed the code. I guess that's what happens when you bang out code inside SO without testing first =)
Rich
+1  A: 

I think that the blog entry by Raymond Chen pointed to in the first link gives you an idea of where you want to go. Basically, you would call EnumWindows and then apply that algorithm, except that you would take note of every window handle that is visible.

The question is a little vague, what is the purpose here (there might be a better way given more info).

casperOne
I can't see it. perhaps I'm blind (or just mad). could you suggest a couple of lines of code?
AJ
A: 

Just use EW() api (win32 FAQ)