示例#1
0
        /// <summary>
        /// Shows the toast notification using native Win32 APIs.
        /// </summary>
        /// <param name="toast">ToatsNotification as created in the native library.</param>
        public static async Task Show(this ToastNotification toast)
        {
            Icon icon;

            if (toast.AppLogoOverride != null)
            {
                var imageStream = await toast.AppLogoOverride.GetStreamAsync().ConfigureAwait(false);

                var bitmap = (Bitmap)Image.FromStream(imageStream);
                icon = Icon.FromHandle(bitmap.GetHicon());
            }
            else
            {
                icon = GetProcessIcon();
            }

            lock (dummy)
            {
                var notifyData = new NotificationIconData();
                notifyData.hWnd   = Process.GetCurrentProcess().MainWindowHandle;
                notifyData.cbSize = (uint)Marshal.SizeOf(notifyData);
                notifyData.DUMMYUNIONNAME_uTimeout_uVersion = 0x4;
                notifyData.hIcon    = GetProcessIcon().Handle;
                notifyData.szTip    = string.Empty;
                notifyData.uFlags   = NotificationIconFlags.Icon | NotificationIconFlags.Tip | NotificationIconFlags.Guid;
                notifyData.guidItem = id;

                notifyData.AddIcon();

                notifyData.uFlags       = NotificationIconFlags.Info | NotificationIconFlags.Icon | NotificationIconFlags.Guid;
                notifyData.szInfoTitle  = toast.Title;
                notifyData.szInfo       = toast.Message;
                notifyData.dwInfoFlags  = NotificationIconInfoFlags.User | NotificationIconInfoFlags.LargeIcon;
                notifyData.hBalloonIcon = icon.Handle;

                Shell.NotifyIcon(NotificationIconMessage.Modify, notifyData);

                // Extra 1500ms for the notification to fade out:
                Thread.Sleep(GetNotificationDuration() * 1000 + 1500);
                notifyData.RemoveIcon();
            }
        }
示例#2
0
 private static void RemoveIcon(this NotificationIconData notifyData)
 {
     Shell.NotifyIcon(NotificationIconMessage.Delete, notifyData);
 }
示例#3
0
 private static void AddIcon(this NotificationIconData notifyData)
 {
     Shell.NotifyIcon(NotificationIconMessage.Add, notifyData);
     Shell.NotifyIcon(NotificationIconMessage.SetVersion, notifyData);
 }