Creating a flashing taskbar icon using FlashWindow with XAML

Looking to notify your users when an application wants its needs met? A sure fire way is to have its taskbar icon flash. Here’s how.

First, import those namespaces, people:

using System.Windows.Interop;
 using System.Runtime.InteropServices;

Next, declare the Windows API FlashWindow method.

[DllImport("user32")] public static extern int FlashWindow(IntPtr hwnd, bool bInvert);

Notice the first parameter is a IntPtr, NOT an int, like I found at one of the websites I visited trying to get this working. An int will get you nowhere. IntPtr is your friend.

Now create a WindowInteropHelper by passing the WPF Window object that you are calling the code from. Pass the window’s Handle property to the FlashWindow method, along with a value of “true”, to tell it that you want the awesome flashing taskbar effect.

WindowInteropHelper wih = new WindowInteropHelper(ThisWindow); 
FlashWindow(wih.Handle, true);

There we go, a simple way to alert users when your application is done or has updated information.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: