Пример #1
0
        /// <summary>
        /// Retrieves all application destinations belonging to the specified
        /// application destination type.
        /// </summary>
        /// <param name="type">The application destination type.</param>
        /// <returns>A copy of the application destinations belonging to
        /// the specified type; modifying the returned objects has no effect
        /// on the application's destination list.</returns>
        public IEnumerable<IJumpListDestination> GetApplicationDestinations(ApplicationDestinationType type)
        {
            if (type == ApplicationDestinationType.None)
                throw new ArgumentException("ApplicationDestinationType can't be NONE");

            IApplicationDocumentLists destinations = (IApplicationDocumentLists)new CApplicationDocumentLists();
            Guid iidObjectArray = typeof(IObjectArray).GUID;
           
            object obj;
            HResult getListResult = destinations.GetList((AppDocListType)type, 100, ref iidObjectArray, out obj);
            getListResult.ThrowIf();

            List<IJumpListDestination> returnValue = new List<IJumpListDestination>();

            Guid iidShellItem = typeof(IShellItem).GUID;
            Guid iidShellLink = typeof(IShellLinkW).GUID;
            IObjectArray array = (IObjectArray)obj;
           
            uint count;
            HResult getCountResult = array.GetCount(out count);
            getCountResult.ThrowIf();

            for (uint i = 0; i < count; ++i)
            {
                try
                {
                    array.GetAt(i, ref iidShellItem, out obj);
                }
                catch (Exception) //Wrong type
                { }

                if (obj == null)
                {
                    HResult getAtResult = array.GetAt(i, ref iidShellLink, out obj);
                    getAtResult.ThrowIf();
                    //This shouldn't fail since if it's not IShellItem
                    //then it must be IShellLink.

                    IShellLinkW link = (IShellLinkW)obj;
                    ShellLink wrapper = new ShellLink();

                    StringBuilder sb = new StringBuilder(256);  
                    HResult getPathResult = link.GetPath(sb, sb.Capacity, IntPtr.Zero, 2);
                    getPathResult.ThrowIf();
                    wrapper.Path = sb.ToString();

                    HResult getArgumentsResult = link.GetArguments(sb, sb.Capacity);
                    getArgumentsResult.ThrowIf();
                    wrapper.Arguments = sb.ToString();

                    int iconId;
                    HResult getIconLocationResult = link.GetIconLocation(sb, sb.Capacity, out iconId);
                    getIconLocationResult.ThrowIf();
                    wrapper.IconIndex = iconId;
                    wrapper.IconLocation = sb.ToString();

                    uint showCmd;
                    HResult getShowCmdResult = link.GetShowCmd(out showCmd);
                    getShowCmdResult.ThrowIf();
                    wrapper.ShowCommand = (WindowShowCommand)showCmd;

                    HResult getWorkingDirectoryResult = link.GetWorkingDirectory(sb, sb.Capacity);
                    getWorkingDirectoryResult.ThrowIf();
                    wrapper.WorkingDirectory = sb.ToString();

                    returnValue.Add(wrapper);
                }
                else //It's an IShellItem.
                {
                    IShellItem item = (IShellItem)obj;
                    ShellItem wrapper = new ShellItem();

                    string path;
                    HResult getDisplayNameResult = item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
                    getDisplayNameResult.ThrowIf();
                    wrapper.Path = path;

                    //Title and Category are irrelevant here, because it's
                    //an IShellItem.  The user might want to see them, but he's
                    //free to go to the IShellItem and look at its property store.

                    returnValue.Add(wrapper);
                }
            }
            return returnValue;
        }
Пример #2
0
 public IEnumerable<IJumpListDestination> GetApplicationDestinations(ApplicationDestinationType type)
 {
     if (type == ApplicationDestinationType.None)
         throw new ArgumentException("ApplicationDestinationType can't be NONE");
     IApplicationDocumentLists destinations = (IApplicationDocumentLists)new CApplicationDocumentLists();
     Guid iidObjectArray = typeof(IObjectArray).GUID;
     object obj;
     HResult getListResult = destinations.GetList((AppDocListType)type, 100, ref iidObjectArray, out obj);
     getListResult.ThrowIf();
     List<IJumpListDestination> returnValue = new List<IJumpListDestination>();
     Guid iidShellItem = typeof(IShellItem).GUID;
     Guid iidShellLink = typeof(IShellLinkW).GUID;
     IObjectArray array = (IObjectArray)obj;
     uint count;
     HResult getCountResult = array.GetCount(out count);
     getCountResult.ThrowIf();
     for (uint i = 0; i < count; ++i)
     {
         try
         {
             array.GetAt(i, ref iidShellItem, out obj);
         }
         catch (Exception)
         { }
         if (obj == null)
         {
             HResult getAtResult = array.GetAt(i, ref iidShellLink, out obj);
             getAtResult.ThrowIf();
             IShellLinkW link = (IShellLinkW)obj;
             ShellLink wrapper = new ShellLink();
             StringBuilder sb = new StringBuilder(256);
             HResult getPathResult = link.GetPath(sb, sb.Capacity, IntPtr.Zero, 2);
             getPathResult.ThrowIf();
             wrapper.Path = sb.ToString();
             HResult getArgumentsResult = link.GetArguments(sb, sb.Capacity);
             getArgumentsResult.ThrowIf();
             wrapper.Arguments = sb.ToString();
             int iconId;
             HResult getIconLocationResult = link.GetIconLocation(sb, sb.Capacity, out iconId);
             getIconLocationResult.ThrowIf();
             wrapper.IconIndex = iconId;
             wrapper.IconLocation = sb.ToString();
             uint showCmd;
             HResult getShowCmdResult = link.GetShowCmd(out showCmd);
             getShowCmdResult.ThrowIf();
             wrapper.ShowCommand = (WindowShowCommand)showCmd;
             HResult getWorkingDirectoryResult = link.GetWorkingDirectory(sb, sb.Capacity);
             getWorkingDirectoryResult.ThrowIf();
             wrapper.WorkingDirectory = sb.ToString();
             returnValue.Add(wrapper);
         }
         else
         {
             IShellItem item = (IShellItem)obj;
             ShellItem wrapper = new ShellItem();
             string path;
             HResult getDisplayNameResult = item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
             getDisplayNameResult.ThrowIf();
             wrapper.Path = path;
             returnValue.Add(wrapper);
         }
     }
     return returnValue;
 }