Question

I am developing an application that controls an Machine.
When I receive an error from the Machine the users should be able to directly notice it, one way that is done is Flashing the tray on the taskbar. When the machine clears the error the tray should stop flashing.

There's one little annoyance using the FlashWindowEx function, when I clear the flashing of the window, it stays (in my case winXP) orange (not flashing).
Sample of status


    [Flags]
        public enum FlashMode {
            /// 
            /// 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
        }

        public static bool FlashWindowEx(IntPtr hWnd, FlashMode fm) {
            FLASHWINFO fInfo = new FLASHWINFO();

            fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
            fInfo.hwnd = hWnd;
            fInfo.dwFlags = (UInt32)fm;
            fInfo.uCount = UInt32.MaxValue;
            fInfo.dwTimeout = 0;

            return FlashWindowEx(ref fInfo);
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct FLASHWINFO {
            public UInt32 cbSize;
            public IntPtr hwnd;
            public UInt32 dwFlags;
            public UInt32 uCount;
            public UInt32 dwTimeout;
        }

In my case I use FLASHW_TRAY to start flashing and FLASHW_STOP to stop the flashing.

Am I doing something wrong or is this a known bug of WinXP and is there a fix for it?

Was it helpful?

Solution

Behaviour is the same when a window finishes flashing for as long as it's supposed to: the taskbar button stays coloured. I don't think this is a bug. If you think about it, when you use FLASHW_STOP, the flashing does in fact stop, but the point of the flashing is to get the user's attention. The button stays coloured because the user still may not have looked down and discovered which window was trying to get her attention. Keeping the button coloured keeps that information available.

OTHER TIPS

Here's an error:

fInfo.uCount = UInt32.MaxValue;

You should set fInfo.uCount to zero when calling with FLASHW_STOP parameter. Otherwise when you try to call stop when taskbar button is active it will stay active.

You can check a note about undefined behavior here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms679348(v=vs.85).aspx

I know that's an old post but it can help other people to solve this problem fast.

Sorry for the late response, I was out of office.

If that's the expected functionality I think it's not so usefull, at least there should be a reset.

I fixed it now just using the FLASHW_ALL | FLASHW_TIMERNOFG combination.

Btw, can't rate your answers, not enough rep yet.

Just set uCount to 0 to stop the flashing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top