tags:

views:

227

answers:

3

Hey all,

Without resorting to PInvoke, is there a way in .net to find out what windows are open? This is slightly different than asking what applications are running in memory. For example, Firefox could be running, but could be more than one window. Basically, I just want to be privy to the same information that the taskbar (and alt-tab?) is.

Also, once I have a reference to a window, is there any way to programatically give it focus?

Is there any way to do this with managed code?

A: 

I'm afraid there is no way you can do it without PInvoke. To give focus to some window you should call SetForegroundWindow function, see this article for details.

aku
+1  A: 

You could check out the new UI Automation stuff in .NET 3.5. It is supposed to mask a whole lot of the PInovke stuff and works with web and WPF applications.

I haven't used it yet, so I don't have a more specific place to direct you, but it might fit the bill.

Steven Murawski
A: 

Check out this LGPL project. I know it can set foreground for a window. Otherwise aku is correct. It'll require most likely some pinvoke calls.

http://mwinapi.sourceforge.net/

If you need information on pinvoke use:

http://www.pinvoke.net/