C# FlashWindowEx FLASHW_STOP 仍然保持任务栏颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FlashWindowEx FLASHW_STOP still keeps taskbar colored
提问by Stormenet
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).
使用 FlashWindowEx 函数有一点烦恼,当我清除窗口的闪烁时,它保持(在我的情况下为 winXP)橙色(不闪烁)。
[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.
就我而言,我使用 FLASHW_TRAY 开始闪烁,使用 FLASHW_STOP 停止闪烁。
Am I doing something wrong or is this a known bug of WinXP and is there a fix for it?
我做错了什么还是这是 WinXP 的已知错误,是否有修复方法?
采纳答案by TheSmurf
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 whichwindow was trying to get her attention. Keeping the button coloured keeps that information available.
当窗口完成闪烁时,行为是一样的:任务栏按钮保持彩色。我不认为这是一个错误。仔细想想,当你使用 FLASHW_STOP 时,闪烁实际上确实停止了,但闪烁的目的是为了引起用户的注意。按钮保持彩色是因为用户可能还没有向下看并发现哪个窗口试图引起她的注意。保持按钮颜色可以保持该信息可用。
回答by Stormenet
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.
我现在只使用FLASHW_ALL | FLASHW_TIMERNOFG
组合修复它。
Btw, can't rate your answers, not enough rep yet.
顺便说一句,无法评价您的答案,还没有足够的代表。
回答by norekhov
Here's an error:
这是一个错误:
fInfo.uCount = UInt32.MaxValue;
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.
使用 FLASHW_STOP 参数调用时,应将 fInfo.uCount 设置为零。否则,当您尝试在任务栏按钮处于活动状态时调用 stop 时,它将保持活动状态。
You can check a note about undefined behavior here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms679348(v=vs.85).aspx
您可以在此处查看有关未定义行为的说明: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.
我知道这是一个旧帖子,但它可以帮助其他人快速解决这个问题。
回答by Sean
Just set uCount to 0 to stop the flashing.
只需将 uCount 设置为 0 即可停止闪烁。