예제 #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("type can't be NONE");

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

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

            Guid iidShellItem = typeof(VistaBridgeInterop.IShellItem).GUID;
            Guid iidShellLink = typeof(IShellLinkW).GUID;
            IObjectArray array = (IObjectArray)obj;
            uint count;
            array.GetCount(out count);
            for (uint i = 0; i < count; ++i)
            {
                try
                {
                    array.GetAt(i, ref iidShellItem, out obj);
                }
                catch (Exception)//Wrong type
                {
                }
                if (obj == null)
                {
                    array.GetAt(i, ref iidShellLink, out obj);
                    //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);
                    link.GetPath(sb, sb.Capacity, IntPtr.Zero, 2);
                    wrapper.Path = sb.ToString();

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

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

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

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

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

                    string path;
                    item.GetDisplayName(
                        VistaBridgeInterop.SafeNativeMethods.SIGDN.SIGDN_FILESYSPATH,
                        out path);
                    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;
        }