Exemplo 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;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the taskbar icons with data provided by a given
        /// <see cref="NotifyIconData"/> instance.
        /// </summary>
        /// <param name="data">Configuration settings for the NotifyIcon.</param>
        /// <param name="command">Operation on the icon (e.g. delete the icon).</param>
        /// <param name="flags">Defines which members of the <paramref name="data"/>
        /// structure are set.</param>
        /// <returns>True if the data was successfully written.</returns>
        /// <remarks>See Shell_NotifyIcon documentation on MSDN for details.</remarks>
        public static bool WriteIconData(ref NotifyIconData data, NotifyCommand command, IconDataMembers flags)
        {
            //do nothing if in design mode
            if (IsDesignMode)
            {
                return(true);
            }

            data.ValidMembers = flags;
            lock (SyncRoot)
            {
                return(WinApi.Shell_NotifyIcon(command, ref data));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a default data structure that provides
        /// a hidden taskbar icon without the icon being set.
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        public static NotifyIconData CreateDefault(IntPtr handle)
        {
            var data = new NotifyIconData();

            if (Environment.OSVersion.Version.Major >= 6)
            {
                //use the current size
                data.cbSize = (uint)Marshal.SizeOf(data);
            }
            else
            {
                //we need to set another size on xp/2003- otherwise certain
                //features (e.g. balloon tooltips) don't work.
                data.cbSize = 952; // NOTIFYICONDATAW_V3_SIZE

                //set to fixed timeout
                data.VersionOrTimeout = 10;
            }

            data.WindowHandle      = handle;
            data.TaskbarIconId     = 0x0;
            data.CallbackMessageId = WindowMessageSink.CallbackMessageId;
            data.VersionOrTimeout  = (uint)NotifyIconVersion.Win95;

            data.IconHandle = IntPtr.Zero;

            //hide initially
            data.IconState = IconState.Hidden;
            data.StateMask = IconState.Hidden;

            //set flags
            data.ValidMembers = IconDataMembers.Message
                                | IconDataMembers.Icon
                                | IconDataMembers.Tip;

            //reset strings
            data.ToolTipText = data.BalloonText = data.BalloonTitle = String.Empty;

            return(data);
        }
Exemplo n.º 4
0
 public static extern bool Shell_NotifyIcon(NotifyCommand cmd, [In] ref NotifyIconData data);
Exemplo n.º 5
0
 /// <summary>
 /// Updates the taskbar icons with data provided by a given
 /// <see cref="NotifyIconData"/> instance.
 /// </summary>
 /// <param name="data">Configuration settings for the NotifyIcon.</param>
 /// <param name="command">Operation on the icon (e.g. delete the icon).</param>
 /// <returns>True if the data was successfully written.</returns>
 /// <remarks>See Shell_NotifyIcon documentation on MSDN for details.</remarks>
 public static bool WriteIconData(ref NotifyIconData data, NotifyCommand command)
 {
     return(WriteIconData(ref data, command, data.ValidMembers));
 }