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
            this.messageSink = Util.IsDesignMode
                ? WindowMessageSink.CreateEmpty()
                : new WindowMessageSink(NotifyIconVersion.Vista);

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

            //create the taskbar icon
            this.CreateTaskbarIcon();

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

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

            // register listener in order to get notified when the application closes
            if (Application.Current != null)
            {
                Application.Current.Exit += this.OnExit;
            }
        }
Esempio n. 2
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;
        }