How to make the taskbar blink my application like Messenger does when a new message arrive?

后端 未结 5 1008
野的像风
野的像风 2020-12-05 08:01

Is there an API call in .NET or a native DLL that I can use to create similar behaviour as Windows Live Messenger when a response comes from someone I chat with?

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 08:11

    FlashWindowEx is the way to go. See here for MSDN documentation

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
    
    [StructLayout(LayoutKind.Sequential)]
    public struct FLASHWINFO
    {
        public UInt32 cbSize;
        public IntPtr hwnd;
        public UInt32 dwFlags;
        public UInt32 uCount;
        public UInt32 dwTimeout;
    }
    
    public const UInt32 FLASHW_ALL = 3; 
    

    Calling the Function:

    FLASHWINFO fInfo = new FLASHWINFO();
    
    fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
    fInfo.hwnd = hWnd;
    fInfo.dwFlags = FLASHW_ALL;
    fInfo.uCount = UInt32.MaxValue;
    fInfo.dwTimeout = 0;
    
    FlashWindowEx(ref fInfo);
    

    This was shamelessly plugged from Pinvoke.net

提交回复
热议问题