示例#1
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 = 504;

            //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;
        }
示例#2
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.BallonToolTipChanged += 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;
        }