Is there a way to tell whether my application is active i.e. any of its windows has .IsActive=true?
I\'m writing messenger app and want it to flash in taskbar when it is
Used P/Invoke and loop
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
private static bool IsActive(Window wnd)
{
// workaround for minimization bug
// Managed .IsActive may return wrong value
if (wnd == null) return false;
return GetForegroundWindow() == new WindowInteropHelper(wnd).Handle;
}
public static bool IsApplicationActive()
{
foreach (var wnd in Application.Current.Windows.OfType())
if (IsActive(wnd)) return true;
return false;
}