La API de Windows (Win32) tiene el método FlashWindowEx dentro de la biblioteca User32 ; este método le permite a usted (el desarrollador) flashear una ventana, significando para el usuario que ocurrió algún evento importante dentro de la aplicación que requiere su atención. El uso más común de este es mostrar la ventana hasta que el usuario vuelva a enfocar la aplicación . Sin embargo, también puede mostrar a la ventana un número especificado de veces, o simplemente seguir destellando hasta que decida cuándo parar.
El uso del método FlashWindowEx, sin embargo, no está integrado en .NET Framework en ninguna parte. Para poder acceder, debe utilizar las funciones de invocación (invocar) de la plataforma de .NET para "soltar" la API de Windows (Win32) y llamarla directamente. Además, como ocurre con muchas otras funcionalidades en la API de Windows (que no están directamente expuestas por .NET), el método FlashWindowEx puede ser un poco complicado de usar si no está familiarizado con el funcionamiento de la API de Windows desde el . RED.
Ahora en lugar de ir demasiado profundo en los detalles de PInvoke o el método FlashWindowEx Win32 , a continuación es una clase estática simple en C# que permite que le permite utilizar fácilmente este método. En realidad, se necesita bastante información sobre para explicar cómo usar PInvoke para utilizar la API de Windows (Win32), así que tal vez lo cubra en un artículo futuro.
He aquí algunos ejemplo de uso de esta clase estática:
// One this to note with this example usage code, is the "this" keyword is referring to
// the current System.Windows.Forms.Form.
// Flash window until it recieves focus
FlashWindow.Flash(this);
// Flash window 5 times
FlashWindow.Flash(this, 5);
// Start Flashing "Indefinately"
FlashWindow.Start(this);
// Stop the "Indefinate" Flashing
FlashWindow.Stop(this);
Una cosa a tener en cuenta sobre el método FlashWindowEx es que requiere (y sólo funcionará en) de Windows 2000 o posterior.
Aquí está el código de la clase estática en C#:
public static class FlashWindow
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
[StructLayout(LayoutKind.Sequential)]
private struct FLASHWINFO
{
/// <summary>
/// The size of the structure in bytes.
/// </summary>
public uint cbSize;
/// <summary>
/// A Handle to the Window to be Flashed. The window can be either opened or minimized.
/// </summary>
public IntPtr hwnd;
/// <summary>
/// The Flash Status.
/// </summary>
public uint dwFlags;
/// <summary>
/// The number of times to Flash the window.
/// </summary>
public uint uCount;
/// <summary>
/// The rate at which the Window is to be flashed, in milliseconds. If Zero, the function uses the default cursor blink rate.
/// </summary>
public uint dwTimeout;
}
/// <summary>
/// Stop flashing. The system restores the window to its original stae.
/// </summary>
public const uint FLASHW_STOP = 0;
/// <summary>
/// Flash the window caption.
/// </summary>
public const uint FLASHW_CAPTION = 1;
/// <summary>
/// Flash the taskbar button.
/// </summary>
public const uint FLASHW_TRAY = 2;
/// <summary>
/// Flash both the window caption and taskbar button.
/// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
/// </summary>
public const uint FLASHW_ALL = 3;
/// <summary>
/// Flash continuously, until the FLASHW_STOP flag is set.
/// </summary>
public const uint FLASHW_TIMER = 4;
/// <summary>
/// Flash continuously until the window comes to the foreground.
/// </summary>
public const uint FLASHW_TIMERNOFG = 12;
/// <summary>
/// Flash the spacified Window (Form) until it recieves focus.
/// </summary>
/// <param name="form">The Form (Window) to Flash.</param>
/// <returns></returns>
public static bool Flash(System.Windows.Forms.Form form)
{
// Make sure we're running under Windows 2000 or later
if (Win2000OrLater)
{
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL | FLASHW_TIMERNOFG, uint.MaxValue, 0);
return FlashWindowEx(ref fi);
}
return false;
}
private static FLASHWINFO Create_FLASHWINFO(IntPtr handle, uint flags, uint count, uint timeout)
{
FLASHWINFO fi = new FLASHWINFO();
fi.cbSize = Convert.ToUInt32(Marshal.SizeOf(fi));
fi.hwnd = handle;
fi.dwFlags = flags;
fi.uCount = count;
fi.dwTimeout = timeout;
return fi;
}
/// <summary>
/// Flash the specified Window (form) for the specified number of times
/// </summary>
/// <param name="form">The Form (Window) to Flash.</param>
/// <param name="count">The number of times to Flash.</param>
/// <returns></returns>
public static bool Flash(System.Windows.Forms.Form form, uint count)
{
if (Win2000OrLater)
{
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, count, 0);
return FlashWindowEx(ref fi);
}
return false;
}
/// <summary>
/// Start Flashing the specified Window (form)
/// </summary>
/// <param name="form">The Form (Window) to Flash.</param>
/// <returns></returns>
public static bool Start(System.Windows.Forms.Form form)
{
if (Win2000OrLater)
{
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, uint.MaxValue, 0);
return FlashWindowEx(ref fi);
}
return false;
}
/// <summary>
/// Stop Flashing the specified Window (form)
/// </summary>
/// <param name="form"></param>
/// <returns></returns>
public static bool Stop(System.Windows.Forms.Form form)
{
if (Win2000OrLater)
{
FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_STOP, uint.MaxValue, 0);
return FlashWindowEx(ref fi);
}
return false;
}
/// <summary>
/// A boolean value indicating whether the application is running on Windows 2000 or later.
/// </summary>
private static bool Win2000OrLater
{
get { return System.Environment.OSVersion.Version.Major >= 5; }
}
}
Salida http://stackoverflow.com/questions/ 8924556/fuerza-window-a-parpadeo cuando-a-concreto-caso-ocurre-in-c-sharp-WPF/8929473 # 8929473, que tiene Q y a –