Esempio n. 1
0
        /// <summary>
        /// Inits the taskbar icon and registers a message listener
        /// in order to receive events from the taskbar area.
        /// </summary>
        public TaskbarIcon()
        {
            //using dummy sink in design mode
            messageSink = Util.IsDesignMode
                ? WindowMessageSink.CreateEmpty()
                : new WindowMessageSink(NotifyIconVersion.Win95);

            //init icon data structure
            iconData = NotifyIconData.CreateDefault(messageSink.MessageWindowHandle);

            //create the taskbar icon
            CreateTaskbarIcon();

            //register event listeners
            messageSink.MouseEventReceived        += OnMouseEvent;
            messageSink.TaskbarCreated            += OnTaskbarCreated;
            messageSink.ChangeToolTipStateRequest += OnToolTipChange;
            messageSink.BalloonToolTipChanged     += OnBalloonToolTipChanged;

            //init single click / balloon timers
            singleClickTimer  = new Timer(DoSingleClickAction);
            balloonCloseTimer = new Timer(CloseBalloonCallback);

            //register listener in order to get notified when the application closes
            if (Application.Current != null)
            {
                Application.Current.Exit += OnExit;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the taskbar icon and registers a message listener
        /// in order to receive events from the taskbar area.
        /// </summary>
        public TaskBarIcon(Icon icon)
        {
            Icon = icon;

            // using dummy sink in design mode
            messageSink = new WindowMessageSink(NotifyIconVersion.Vista);

            // init icon data structure
            iconData             = NotifyIconData.CreateDefault(messageSink.MessageWindowHandle);
            iconData.IconHandle  = Icon?.Handle ?? IntPtr.Zero;
            iconData.ToolTipText = nameof(MangaReader);

            // create the taskbar icon
            CreateTaskbarIcon();

            // register event listeners
            messageSink.MouseEventReceived += OnMouseEvent;
            messageSink.TaskbarCreated     += OnTaskbarCreated;

            // register listener in order to get notified when the application closes
            if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
            {
                lifetime.Exit += OnExit;
            }
        }
        /// <summary>
        /// Hook into Windows message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnMainWindowSourceInitialized(object sender, EventArgs e)
        {
            ServiceRegistration.Get <ILogger>().Debug("OnMainWindowSourceInitialized");
            ((Window)sender).SourceInitialized -= OnMainWindowSourceInitialized;

            _messageSink            = new WindowMessageSink();
            _messageSink.OnWinProc += WndProc;
        }
Esempio n. 4
0
        public NotificationIcon()
        {
            MessageSink = WPFUtil.IsDesignMode ? WindowMessageSink.CreateEmpty() : new WindowMessageSink();
            IconData    = Shell32.NOTIFYICONDATA.New(MessageSink.HWnd, WindowMessageSink.CallbackMessageId, Shell32.ENotifyIconVersion.Win95);

            // Commands
            ShowCMenu = Command.Create(this, ShowCMenuInternal);
            ShowOwner = Command.Create(this, ShowOwnerInternal);

            // Default actions
            LeftClickCommand  = ShowOwner;
            RightClickCommand = ShowCMenu;
        }
        public void Dispose()
        {
            if (_messageSink == null)
            {
                return;
            }

            _messageSink.OnWinProc -= WndProc;
            _messageSink.Dispose();
            _messageSink = null;

            _taskbarIcon.Visibility = Visibility.Collapsed;
            _taskbarIcon.Dispose();
            _taskbarIcon = null;
        }