Search code examples
.netwinapimonopinvoke

Managed alternative to user32.dll FlashWindow


In a .Net application that flashes the title bar and the corresponding taskbar button for a window, to attract the users' attention, P/Invoke code something like this is used:

[DllImport("user32.dll")]
private static extern bool FlashWindow(IntPtr hwnd, bool bInvert);

public static void FlashWindow(System.Windows.Forms.Form window)
{
  FlashWindow(window.Handle, false);
}

How can the same effect be triggered without using P/Invokes? Specifically, the .Net application is being updated to run fully on Linux/Mac OS X with Mono. Is there any way to construct a managed equivalent to FlashWindow or FlashWindowEx?


Solution

  • You should note that Microsoft's own UI guidelines suggest that you should not do this unless the event really does require immediate attention.

    Don't flash the taskbar button if the only thing the user has to do is activate the program, read a message, or see a change in status.

    It is strongly advisable, even within a cross platform app, that the current system's UI guidelines are followed.
    In this case it depends what you are trying to do but taking a guess:

    If you really do want to do the equivalent of the Flashing window icon the equivalent on OS X would be a bouncing dock icon (Again, people don't like this). I don't know if that is wrapped by cocoa#.

    In Linux the behaviour is again fragmented since many frameworks simply don't have the taskbar concept and you would be expected to play nicely with whatever framework you were in.