ZeroInstall.Hooking.WindowsTaskbar.AddTaskLinks C# (CSharp) Method

AddTaskLinks() private method

private AddTaskLinks ( string appID, IEnumerable links ) : void
appID string
links IEnumerable
return void
        public static void AddTaskLinks(string appID, IEnumerable<ShellLink> links)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(appID)) throw new ArgumentNullException(nameof(appID));
            if (links == null) throw new ArgumentNullException(nameof(links));
            #endregion

            if (!WindowsUtils.IsWindows7) return;

            try
            {
                var customDestinationList = (ICustomDestinationList)new CDestinationList();
                customDestinationList.SetAppID(appID);

                var objectArray = new Guid("92CA9DCD-5622-4BBA-A805-5E9F541BD8C9");
                object removedItems;
                uint maxSlots;
                customDestinationList.BeginList(out maxSlots, ref objectArray, out removedItems);

                var taskContent = (IObjectCollection)new CEnumerableObjectCollection();
                foreach (var shellLink in links)
                    taskContent.AddObject(ConvertShellLink(shellLink));

                customDestinationList.AddUserTasks((IObjectArray)taskContent);
                customDestinationList.CommitList();
            }
            catch
            {}
        }

Usage Example

示例#1
0
        /// <summary>
        /// Applies relaunch command and jump list modifications to a Windows 7 taskbar entry.
        /// </summary>
        /// <param name="windowHandle">A handle to the window the taskbar entry belongs to.</param>
        private void ConfigureTaskbar(IntPtr windowHandle)
        {
            if (_relaunchInformation == null || !WindowsUtils.IsWindows7)
            {
                return;
            }

            // Add correct relaunch information
            string commandPath = (_relaunchInformation.NeedsTerminal ? _relaunchControl.CommandPathCli : _relaunchControl.CommandPathGui + " --no-wait"); // Select best suited launcher
            string icon        = (string.IsNullOrEmpty(_relaunchInformation.IconPath) ? null : _relaunchInformation.IconPath + ",0");                     // Always use the first icon in the file

            WindowsTaskbar.SetWindowAppID(windowHandle,
                                          _relaunchInformation.AppID, '"' + commandPath + "\" run " + _relaunchInformation.Target, icon, _relaunchInformation.Name);

            // Add jump list entry to select an alternative application version
            WindowsTaskbar.AddTaskLinks(_relaunchInformation.AppID, new[] { new WindowsTaskbar.ShellLink("Versions", _relaunchControl.CommandPathGui, "run --customize " + _relaunchInformation.Target) });
        }