Esempio n. 1
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)
 {
     data.ValidMembers = flags;
     lock (SyncRoot)
     {
         return(WinApi.Shell_NotifyIcon(command, ref data));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Creates a default data structure that provides
        /// a hidden taskbar icon without the icon being set.
        /// </summary>
        /// <param name="handle"></param>
        /// <returns>NotifyIconData</returns>
        public static NotifyIconData CreateDefault(IntPtr handle, string iconFile)
        {
            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)0x4;

            IntPtr hIcon = PInvoke.User32.LoadImage(IntPtr.Zero, iconFile,
                                                    PInvoke.User32.ImageType.IMAGE_ICON, 16, 16, PInvoke.User32.LoadImageFlags.LR_LOADFROMFILE);

            data.IconHandle = hIcon;

            //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);
        }
Esempio n. 3
0
        public WindowsTrayIcon(string iconFile)
        {
            messageSink = new WindowMessageSink();

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

            //IntPtr hIcon = PInvoke.User32.LoadImage(IntPtr.Zero, "dotnetbot.ico",
            //    PInvoke.User32.ImageType.IMAGE_ICON, 16, 16, PInvoke.User32.LoadImageFlags.LR_LOADFROMFILE);

            //PInvoke.User32.SendMessage(iconData.WindowHandle, PInvoke.User32.WindowMessage.WM_SETICON, (IntPtr)0, hIcon);

            // create the taskbar icon
            CreateTaskbarIcon();

            // register event listeners
            messageSink.MouseEventReceived += MessageSink_MouseEventReceived;
            messageSink.TaskbarCreated     += MessageSink_TaskbarCreated;
            //messageSink.ChangeToolTipStateRequest += OnToolTipChange;
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a default data structure that provides
        /// a hidden taskbar icon without the icon being set.
        /// </summary>
        /// <param name="handle"></param>
        /// <returns>NotifyIconData</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 = (int)NativeConsts.Message.WM_USER;
            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);
        }
Esempio n. 5
0
        public static NotifyIconData CreateDefault(IntPtr handle)
        {
            NotifyIconData structure = new NotifyIconData();

            if (Environment.OSVersion.Version.Major >= 6)
            {
                structure.cbSize = (uint)Marshal.SizeOf <NotifyIconData>(structure);
            }
            else
            {
                structure.cbSize           = 0x1f8;
                structure.VersionOrTimeout = 10;
            }
            structure.WindowHandle      = handle;
            structure.TaskbarIconId     = 0;
            structure.CallbackMessageId = 0x400;
            structure.VersionOrTimeout  = 0;
            structure.IconHandle        = IntPtr.Zero;
            structure.IconState         = Hardcodet.Wpf.TaskbarNotification.Interop.IconState.Hidden;
            structure.StateMask         = Hardcodet.Wpf.TaskbarNotification.Interop.IconState.Hidden;
            structure.ValidMembers      = IconDataMembers.Tip | IconDataMembers.Icon | IconDataMembers.Message;
            structure.ToolTipText       = structure.BalloonText = structure.BalloonTitle = string.Empty;
            return(structure);
        }
    /// <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;
    }
        /// <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. 8
0
 public static extern bool Shell_NotifyIcon(NotifyCommand cmd, [In] ref NotifyIconData data);
Esempio n. 9
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));
 }