任务栏通知发光

use*_*715 3 c# winforms

我有一个TCP聊天应用程序.当新消息到来时,我想让任务栏发光,直到用户再次打开表单(如果没有焦点/激活).

我的意思的一个例子:http: //puu.sh/4z01n.png

我怎么能让它像那样发光?

谢谢!

如果你仍然不明白我的意思..我提供的图像是当任何"发光"的东西出现在任务栏上的图标上.意思是有一个通知.这就是我想要实现的目标.

Men*_*gis 5

我希望这能帮到您

[DllImport("User32.dll")]
[return:MarshalAs(UnmanagedType.Bool)]
static extern bool FlashWindowEx(ref FLASHINFO pwfi);


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


[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 FlashWindow(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);
        }
Run Code Online (Sandbox Code Playgroud)

摘自Flashing Taskbar中的 wiki