C# Win32 API: Flash Window (FlashWindowEx)
Ever tried to flash a window using managed code ? The following method will flash the window title bar or the window taskbar button. Since there is no managed API available for this functionality - need to wrap a method imported from user32: FlashWindowEx:
[DllImport("user32.dll")]
static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);
Where FLASHWINFO struct is defined like so:
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public Int32 dwFlags;
public UInt32 uCount;
public Int32 dwTimeout;
}
Where dwFlags can be one of the following:
// stop flashing FLASHW_STOP = 0; // flash the window title FLASHW_CAPTION = 1; // flash the taskbar button FLASHW_TRAY = 2; // 1 | 2 FLASHW_ALL = 3; // flash continuously FLASHW_TIMER = 4; // flash until the window comes to the foreground FLASHW_TIMERNOFG = 12;
So the typical C# call will look like so:
public static bool Flash()
{
FLASHWINFO fw = new FLASHWINFO();
fw.cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(FLASHWINFO)));
fw.hwnd = this.Handle;
fw.dwFlags = 2;
fw.uCount = UInt32.MaxValue;
FlashWindowEx(ref fw);
}
See some other C# Win32 API tips and tricks. Enjoy :)
Saturday, April 19, 2008 9:11 PM