Exemplo n.º 1
0
        /// <summary>
        /// Initializes 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;
            }
        }