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