private bool BeginList() { if (UserRemovedItems == null) { throw new InvalidOperationException( "You must register for the JumpListManager.UserRemovedItems event before adding any items"); } object obj; _customDestinationList.BeginList( out _maxSlotsInList, ref SafeNativeMethods.IID_IObjectArray, out obj); IObjectArray removedItems = (IObjectArray)obj; uint count; removedItems.GetCount(out count); if (count == 0) { return(true); } string[] removedItemsArr = new string[count]; for (uint i = 0; i < count; ++i) { object item; removedItems.GetAt(i, ref SafeNativeMethods.IID_IUnknown, out item); try { IShellLinkW shellLink = (IShellLinkW)item; if (shellLink != null) { StringBuilder sb = new StringBuilder(256); shellLink.GetPath(sb, sb.Capacity, IntPtr.Zero, 2); removedItemsArr[i] = sb.ToString(); } continue; } catch (InvalidCastException)//It's not a shell link { } try { VistaBridgeInterop.IShellItem shellItem = (VistaBridgeInterop.IShellItem)item; if (shellItem != null) { string path; shellItem.GetDisplayName( VistaBridgeInterop.SafeNativeMethods.SIGDN.SIGDN_FILESYSPATH, out path); removedItemsArr[i] = path; } } catch (InvalidCastException) { //It's neither a shell link nor a shell item. //This is impossible. Debug.Assert(false, "List of removed items contains something that is neither a shell item nor a shell link"); } } UserRemovedItemsEventArgs args = new UserRemovedItemsEventArgs(removedItemsArr); UserRemovedItems(this, args); if (args.CancelCurrentOperation) { _customDestinationList.AbortList(); } return(!args.CancelCurrentOperation); }
/// <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); }