<p>I am developing an application that controls an Machine.<br/>
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.</p>
<p>There's one little annoyance using the <code>FlashWindowEx</code> function, when I clear the flashing of the window, it stays (in my case WinXP) orange (not flashing).</p>
<p><a href="https://i.stack.imgur.com/GOS2r.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GOS2r.gif" alt="" /></a></p>
<pre><code>[Flags]
public enum FlashMode {
    /// &lt;summary&gt;
    /// Stop flashing. The system restores the window to its original state.
    /// &lt;/summary&gt;
    FLASHW_STOP = 0,
    /// &lt;summary&gt;
    /// Flash the window caption.
    /// &lt;/summary&gt;
    FLASHW_CAPTION = 1,
    /// &lt;summary&gt;
    /// Flash the taskbar button.
    /// &lt;/summary&gt;
    FLASHW_TRAY = 2,
    /// &lt;summary&gt;
    /// Flash both the window caption and taskbar button.
    /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
    /// &lt;/summary&gt;
    FLASHW_ALL = 3,
    /// &lt;summary&gt;
    /// Flash continuously, until the FLASHW_STOP flag is set.
    /// &lt;/summary&gt;
    FLASHW_TIMER = 4,
    /// &lt;summary&gt;
    /// Flash continuously until the window comes to the foreground.
    /// &lt;/summary&gt;
    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;
}
</code></pre>
<p>In my case I use <code>FLASHW_TRAY</code> to start flashing and <code>FLASHW_STOP</code> to stop the flashing.</p>
<p>Am I doing something wrong or is this a known bug of WinXP and is there a fix for it?</p>

[{'answer_id': 23285, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 4, 'selected': True, 'text': "<p>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 <code>FLASHW_STOP</code>, 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 <em>which</em> window was trying to get her attention. Keeping the button coloured keeps that information available.</p>\n"}, {'answer_id': 37615, 'author': 'Stormenet', 'author_id': 2090, 'author_profile': 'https://Stackoverflow.com/users/2090', 'pm_score': 0, 'selected': False, 'text': "<p>If that's the expected functionality I think it's not so useful, at least there should be a reset.</p>\n<p>I fixed it now just using the <code>FLASHW_ALL | FLASHW_TIMERNOFG</code> combination.</p>\n"}, {'answer_id': 22200798, 'author': 'norekhov', 'author_id': 2794542, 'author_profile': 'https://Stackoverflow.com/users/2794542', 'pm_score': 2, 'selected': False, 'text': '<p>Here\'s an error:</p>\n\n<blockquote>\n  <p>fInfo.uCount = UInt32.MaxValue;</p>\n</blockquote>\n\n<p>You should set fInfo.uCount to zero when calling with FLASHW_STOP parameter. \nOtherwise when you try to call stop when taskbar button is active it will stay active.</p>\n\n<p>You can check a note about undefined behavior here:\n<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms679348(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ms679348(v=vs.85).aspx</a></p>\n\n<p>I know that\'s an old post but it can help other people to solve this problem fast.</p>\n'}, {'answer_id': 36740046, 'author': 'Sean', 'author_id': 4143886, 'author_profile': 'https://Stackoverflow.com/users/4143886', 'pm_score': -1, 'selected': False, 'text': '<p>Just set uCount to 0 to stop the flashing.</p>\n'}, {'answer_id': 67506261, 'author': 'flyguille', 'author_id': 2784000, 'author_profile': 'https://Stackoverflow.com/users/2784000', 'pm_score': -1, 'selected': False, 'text': '<p>fixed with uCount=0</p>\n<p>if (flags = FLASHW_STOP) { .uCount = 0 } else { .uCount = 800 }</p>\n<p>The misbehaviour is that if you are calling flashw_stop from a click/kb event from inside the Window itself, the taskbar button stay colored if a that moment was colored.</p>\n<p>With that new logic line, done.</p>\n'}]
['https://Stackoverflow.com/questions/21987', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2090/']