Alin Popa
Alin Popa

Reputation: 211

Win32API for window focalization

I want to use API functions to set focus on one window under Windows (XP , Vista , 7 (whatever , any version who support .NET 3.0 or later)). So that when you press a key , the OS changes focus to another window.

Thanks

P.S: If you know any class in .NET 2.0 (or later) with which I can develop this solution I'd like you to tell me about it.

Upvotes: 2

Views: 542

Answers (1)

Kevin Montrose
Kevin Montrose

Reputation: 22571

You could p/invoke SetForegroundWindow. This will bring a window forward and focus on it.

This does require that you have the windows HWND.

As a side note, user's do not appreciate unexpectedly focusing a window; so use with caution. Additionally, Windows will not necessarily actually bring the window forward; it may instead just "flash" the title bar under some circumstances.

Upvotes: 2

Related Questions