1
votes

How do I Flash TaskBar icon of external application? I have tried FlashWindowEx and checked it out onpInvoke.net and also http://pietschsoft.com/post/2009/01/26/CSharp-Flash-Window-in-Taskbar-via-Win32-FlashWindowEx but that only deals with flashing the current Form (this). I can't make it Flash an external window though.

I have got a hWnd (IntPtr) and also a process.MainWindowHandle to the external app that I want to flash, but I don't know how to use FlashWindowEx to flash the external window.

1

1 Answers

1
votes

When you call FlashWindowEx, just pass the MainWindowHandle of the other application you want to flash. For example, you can use the FlashOtherWindow function shown below, passing in the handle.

    [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;
    }

    internal static void FlashOtherWindow(IntPtr windowHandle)
    {
        FLASHWINFO fInfo = new FLASHWINFO();
        fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
        fInfo.dwFlags = 2;
        fInfo.dwTimeout = 0;
        fInfo.hwnd = windowHandle;
        fInfo.uCount = 3;

        FlashWindowEx(ref fInfo);
    }

    internal static void FlashApplicationWindow(string application)
    {
        foreach (Process process in Process.GetProcessesByName(application))
            FlashOtherWindow(process.MainWindowHandle);
    }

I also included FlashApplicationWindow that takes the name of the application. You can use it like so:

    FlashApplicationWindow("firefox");