1

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!

Wezley
  • 413
  • 1
  • 3
  • 19
  • Looks like a duplicate of http://stackoverflow.com/questions/115868/how-do-i-get-the-title-of-the-current-active-window-using-c – Pranav Negandhi Jul 01 '13 at 04:55

1 Answers1

2

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#.

Pieter van Ginkel
  • 29,160
  • 8
  • 71
  • 111