コード例 #1
0
        /// <summary>
        /// Creates the taskbar icon. This message is invoked during initialization,
        /// if the taskbar is restarted, and whenever the icon is displayed.
        /// </summary>
        private void CreateTaskbarIcon()
        {
            lock (this)
            {
                if (!IsTaskbarIconCreated)
                {
                    const IconDataMembers members = IconDataMembers.Message
                                                    | IconDataMembers.Icon
                                                    | IconDataMembers.Tip;

                    //write initial configuration
                    var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members);
                    if (!status)
                    {
                        throw new Win32Exception("Could not create icon data");
                    }

                    //set to most recent version
                    SetVersion();
                    messageSink.Version = (NotifyIconVersion)iconData.VersionOrTimeout;

                    IsTaskbarIconCreated = true;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates the taskbar icon. This message is invoked during initialization,
        /// if the taskbar is restarted, and whenever the icon is displayed.
        /// </summary>
        private void CreateTaskbarIcon()
        {
            lock (this.SyncLock)
            {
                if (!IsTaskbarIconCreated)
                {
                    const IconDataMembers members = IconDataMembers.Message
                                                    | IconDataMembers.Icon
                                                    | IconDataMembers.Tip;

                    //write initial configuration
                    var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members);
                    if (!status)
                    {
                        //couldn't create the icon - we can assume this is because explorer is not running (yet!)
                        //-> try a bit later again rather than throwing an exception. Typically, if the windows
                        // shell is being loaded later, this method is being reinvoked from OnTaskbarCreated
                        // (we could also retry after a delay, but that's currently YAGNI)
                        return;
                    }

                    //set to most recent version
                    SetVersion();
                    messageSink.Version = iconData.VersionOrTimeout;

                    IsTaskbarIconCreated = true;
                }
            }
        }
コード例 #3
0
ファイル: TaskbarIcon.cs プロジェクト: metaseed/MetaStudio
        /// <summary>
        /// Creates the taskbar icon. This message is invoked during initialization,
        /// if the taskbar is restarted, and whenever the icon is displayed.
        /// </summary>
        private void CreateTaskbarIcon()
        {
            lock (this)
            {
                if (!IsTaskbarIconCreated)
                {
                    const IconDataMembers members = IconDataMembers.Message
                                                    | IconDataMembers.Icon
                                                    | IconDataMembers.Tip;

                    //write initial configuration
                    var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members);
                    if (!status)
                    {
                        //couldn't create the icon - we can assume this is because explorer is not running (yet!)
                        return;
                    }

                    //set to most recent version
                    SetVersion();
                    messageSink.Version = (NotifyIconVersion)iconData.VersionOrTimeout;

                    IsTaskbarIconCreated = true;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates the taskbar icon. This message is invoked during initialization,
        /// if the taskbar is restarted, and whenever the icon is displayed.
        /// </summary>
        private void CreateTaskbarIcon()
        {
            lock (this)
            {
                //此处的try-catch语句由K.F.Storm添加。当explorer.exe没有启动时,原作者的版本会报错,但豆瓣电台不允许崩溃。
                try
                {
                    if (!IsTaskbarIconCreated)
                    {
                        const IconDataMembers members = IconDataMembers.Message
                                                        | IconDataMembers.Icon
                                                        | IconDataMembers.Tip;

                        //write initial configuration
                        var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members);
                        if (!status)
                        {
                            throw new Win32Exception("Could not create icon data");
                        }

                        //set to most recent version
                        SetVersion();
                        messageSink.Version = (NotifyIconVersion)iconData.VersionOrTimeout;

                        IsTaskbarIconCreated = true;
                    }
                }
                catch
                {
                }
            }
        }
コード例 #5
0
ファイル: NotifyIcon.cs プロジェクト: marciorela/testes
 /// <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>
 private bool WriteIconData(ref NotifyIconData data, NotifyCommand command, IconDataMembers flags)
 {
     data.ValidMembers |= flags;
     lock (lockObject)
     {
         return(WinApi.Shell_NotifyIcon(command, ref data));
     }
 }
コード例 #6
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 bool WriteIconData(ref NotifyIconData data, NotifyCommand command, IconDataMembers flags)
        {
            //do nothing if in design mode
            if (IsDesignMode)
            {
                return(true);
            }

            data.ValidMembers = flags;
            lock (lockObject)
            {
                return(Interop.Shell_NotifyIcon(command, ref data));
            }
        }
コード例 #7
0
        /// <summary>
        ///     Sets tooltip settings for the class depending on defined
        ///     dependency properties and OS support.
        /// </summary>
        private void WriteToolTipSettings()
        {
            const IconDataMembers flags = IconDataMembers.Tip;

            iconData.ToolTipText = ToolTipText;
            if (messageSink.Version == NotifyIconVersion.Vista)
            {
                //we need to set a tooltip text to get tooltip events from the
                //taskbar icon
                if (String.IsNullOrEmpty(iconData.ToolTipText) && TrayToolTipResolved != null)
                {
                    //if we have not tooltip text but a custom tooltip, we
                    //need to set a dummy value (we're displaying the ToolTip control, not the string)
                    iconData.ToolTipText = "ToolTip";
                }
            }

            //update the tooltip text
            Util.WriteIconData(ref iconData, NotifyCommand.Modify, flags);
        }
コード例 #8
0
        /// <summary>
        /// Creates the taskbar icon. This message is invoked during initialization, if the taskbar is restarted, and whenever the icon is displayed.
        /// </summary>
        private void CreateIcon()
        {
            lock (this)
            {
                if (!this.IsIconCreated)
                {
                    const IconDataMembers Members = IconDataMembers.Message | IconDataMembers.Icon | IconDataMembers.Tip;

                    // write initial configuration
                    var status = Utilities.WriteIconData(ref this.iconData, NotifyCommand.Add, Members);
                    if (!status)
                    {
                        throw new Win32Exception(Properties.Resources.CouldNotCreateIcon_Data);
                    }

                    // set to most recent version
                    this.SetVersion();
                    this.messageSink.Version = (NotifyIconVersion)this.iconData.VersionOrTimeout;

                    this.IsIconCreated = true;
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Sets tooltip settings for the class depending on defined dependency properties and OS support.
        /// </summary>
        private void WriteToolTipSettings()
        {
            const IconDataMembers Flags = IconDataMembers.Tip;

            this.iconData.ToolTipText = this.ToolTipText;

            if (this.messageSink.Version == NotifyIconVersion.Vista)
            {
                // we need to set a tooltip text to get tooltip events from the
                // taskbar icon
                if (string.IsNullOrEmpty(this.iconData.ToolTipText) && this.TrayToolTipResolved != null)
                {
                    // if we have not tooltip text but a custom tooltip, we
                    // need to set a dummy value (we're displaying the ToolTip control, not the string)
                    // ReSharper disable LocalizableElement
                    this.iconData.ToolTipText = "ToolTip";

                    // ReSharper restore LocalizableElement
                }
            }

            // update the tooltip text
            Utilities.WriteIconData(ref this.iconData, NotifyCommand.Modify, Flags);
        }
コード例 #10
0
ファイル: Util.cs プロジェクト: metaseed/MetaStudio
        /// <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));
            }
        }
コード例 #11
0
    /// <summary>
    /// Updates the taskbar icons.
    /// </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, NotifyCommands command, IconDataMembers flags)
    {
        if (VisualHelper.IsInDesignMode())
        {
            return(true);
        }

        data.ValidMembers = flags;

        lock (VisualHelper.LockObject)
            return(Native.External.Shell32.Shell_NotifyIcon(command, ref data));
    }
コード例 #12
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));
     }
 }
コード例 #13
0
ファイル: Class3.cs プロジェクト: wangzhaoming/HearthBuddy
        public static bool smethod_2(ref NotifyIconData notifyIconData_0, NotifyCommand notifyCommand_0, IconDataMembers iconDataMembers_0)
        {
            if (Boolean_0)
            {
                return(true);
            }
            notifyIconData_0.ValidMembers = iconDataMembers_0;
            object obj2 = object_0;

            lock (obj2)
            {
                return(Class5.Shell_NotifyIcon(notifyCommand_0, ref notifyIconData_0));
            }
        }
コード例 #14
0
ファイル: Util.cs プロジェクト: fuxunyang/WPFNotifyIcon
        /// <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;
            var status      = false;
            var failedTries = 0;

            while (!status && failedTries < 5)
            {
                lock (SyncRoot)
                {
                    status = WinApi.Shell_NotifyIcon(command, ref data);
                    if (status)
                    {
                        return(status);
                    }
                }

                // handle low powered machines during startup:
                // http://msdn.microsoft.com/en-us/library/bb762159(VS.85).aspx
                failedTries += 1;

                System.Threading.Thread.Sleep(100); // ms
            }

            System.Console.WriteLine("failed to write icon data");
            return(false);
        }