Burton
Burton

Reputation: 343

Get a list of current windows, and give one of them focus, in .Net

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?

Upvotes: 3

Views: 420

Answers (3)

jmatt
jmatt

Reputation:

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/

Upvotes: 1

Steven Murawski
Steven Murawski

Reputation: 11255

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.

Upvotes: 1

aku
aku

Reputation: 124044

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.

Upvotes: 0

Related Questions