FlashWindowEx FLASHW_STOP still keeps taskbar colored
Asked Answered
T

5

7

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?

Tramel answered 22/8, 2008 at 9:42 Comment(0)
A
7

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.

Artistic answered 22/8, 2008 at 19:33 Comment(0)
B
3

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.

Busman answered 5/3, 2014 at 14:37 Comment(1)
FLASHW_STOP + uCount = 0 stops flashing, but it does not clear the taskbar button color, what the question is about.Fomentation
T
0

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

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

Tramel answered 1/9, 2008 at 8:25 Comment(0)
J
-1

Just set uCount to 0 to stop the flashing.

Jandy answered 20/4, 2016 at 9:51 Comment(2)
Add some explanation to your answer.!Lens
FLASHW_STOP + uCount = 0 stops flashing, but it does not clear the taskbar button color, what the question is about.Fomentation
F
-1

fixed with uCount=0

if (flags = FLASHW_STOP) { .uCount = 0 } else { .uCount = 800 }

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.

With that new logic line, done.

Fewell answered 12/5, 2021 at 15:6 Comment(1)
FLASHW_STOP + uCount = 0 stops flashing, but it does not clear the taskbar button color, what the question is about.Fomentation

© 2022 - 2024 — McMap. All rights reserved.