Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FlashWindowEx FLASHW_STOP still keeps taskbar colored

Tags:

c#

pinvoke

winapi

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).

[Flags]
public enum FlashMode {
    /// <summary>
    /// Stop flashing. The system restores the window to its original state.
    /// </summary>
    FLASHW_STOP = 0,
    /// <summary>
    /// Flash the window caption.
    /// </summary>
    FLASHW_CAPTION = 1,
    /// <summary>
    /// Flash the taskbar button.
    /// </summary>
    FLASHW_TRAY = 2,
    /// <summary>
    /// Flash both the window caption and taskbar button.
    /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
    /// </summary>
    FLASHW_ALL = 3,
    /// <summary>
    /// Flash continuously, until the FLASHW_STOP flag is set.
    /// </summary>
    FLASHW_TIMER = 4,
    /// <summary>
    /// Flash continuously until the window comes to the foreground.
    /// </summary>
    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?

like image 622
Stormenet Avatar asked Aug 22 '08 09:08

Stormenet


2 Answers

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.

like image 56
TheSmurf Avatar answered Nov 17 '22 04:11

TheSmurf


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.

like image 27
norekhov Avatar answered Nov 17 '22 03:11

norekhov