using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ServerMonitorApp
{
/// Methods for interacting with the Win32 API.
class Win32Helpers
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}
public const int HWND_BROADCAST = 0xffff;
public static readonly int WM_SHOWMONITOR = RegisterWindowMessage("WM_SHOWMONITOR");
[DllImport("user32")]
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
[DllImport("user32")]
public static extern int RegisterWindowMessage(string message);
public enum FlashWindowFlags : uint
{
///
/// Stop flashing. The system restores the window to its original state.
///
FLASHW_STOP = 0,
///
/// Flash the window caption
///
FLASHW_CAPTION = 1,
///
/// Flash the taskbar button.
///
FLASHW_TRAY = 2,
///
/// Flash both the window caption and taskbar button.
/// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
///
FLASHW_ALL = 3,
///
/// Flash continuously, until the FLASHW_STOP flag is set.
///
FLASHW_TIMER = 4,
///
/// Flash continuously until the window comes to the foreground.
///
FLASHW_TIMERNOFG = 12
}
/// Flashes a window icon in the taskbar.
/// The form to flash.
public static bool FlashWindowEx(Form form)
{
IntPtr hWnd = form.Handle;
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_TRAY;
fInfo.uCount = 10;
fInfo.dwTimeout = 0;
return FlashWindowEx(ref fInfo);
}
/// Stops flashing a window icon in the taskbar.
/// The form to stop flashing.
public static bool StopFlashWindowEx(Form form)
{
IntPtr hWnd = form.Handle;
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP;
fInfo.dwTimeout = 0;
return FlashWindowEx(ref fInfo);
}
}
}