The method below works, except when the focus-only process is focused. This applies to Windows Desktop. He steals the status of the foreground window, but he is not in the foreground.
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
public bool IsForeground()
{
Window window = Application.Current.MainWindow;
IntPtr windowHandle = new WindowInteropHelper(window).Handle;
IntPtr foregroundWindow = GetForegroundWindow();
return windowHandle == foregroundWindow;
}
source
share