Pergunta

How would I be able to detect what window is active and currently being focused on in C#? Likes lets take Windows Media player for example. How would I detect if that window is currently up and being focused on in C#?

Thank you!

Foi útil?

Solução

You can use the Win32 GetForegroundWindow for this. However, this will only get you a handle (a HWND). You will need to use further P/Invoke methods to actually do something useful with this.

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms633505(v=vs.85).aspx for more information on GetForegroundWindow and http://www.pinvoke.net/default.aspx/user32.getforegroundwindow for how to access this from C#.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top