示例#1
0
        private IEnumerable <string> ProcessDeletedItems(IObjectArray removedItems)
        {
            List <string> removedItemsArray = new List <string>();

            uint count;

            removedItems.GetCount(out count);

            // Process each removed item based on its type
            for (uint i = 0; i < count; i++)
            {
                // Native call to retrieve objects from IObjectArray
                object item;
                removedItems.GetAt(i,
                                   ref TaskbarNativeMethods.TaskbarGuids.IUnknown,
                                   out item);

                IShellItem  shellItem = item as IShellItem;
                IShellLinkW shellLink;
                // Process item
                if (shellItem != null)
                {
                    removedItemsArray.Add(RemoveCustomCategoryItem(shellItem));
                }
                else if ((shellLink = item as IShellLinkW) != null)
                {
                    removedItemsArray.Add(RemoveCustomCategoryLink(shellLink));
                }
            }
            return(removedItemsArray);
        }
示例#2
0
        private static List <JumpList._ShellObjectPair> GenerateJumpItems(IObjectArray shellObjects)
        {
            List <JumpList._ShellObjectPair> list = new List <JumpList._ShellObjectPair>();
            Guid guid  = new Guid("00000000-0000-0000-C000-000000000046");
            uint count = shellObjects.GetCount();

            for (uint num = 0u; num < count; num += 1u)
            {
                object   at       = shellObjects.GetAt(num, ref guid);
                JumpItem jumpItem = null;
                try
                {
                    jumpItem = JumpList.GetJumpItemForShellObject(at);
                }
                catch (Exception ex)
                {
                    if (ex is NullReferenceException || ex is SEHException)
                    {
                        throw;
                    }
                }
                list.Add(new JumpList._ShellObjectPair
                {
                    ShellObject = at,
                    JumpItem    = jumpItem
                });
            }
            return(list);
        }
示例#3
0
        private static List <_ShellObjectPair> GenerateJumpItems(IObjectArray shellObjects)
        {
            Debug.Assert(shellObjects != null);
            var retList    = new List <_ShellObjectPair>();
            var unknownIid = new Guid(IID.Unknown);
            var count      = shellObjects.GetCount();

            for (uint i = 0; i < count; ++i)
            {
                var      unk  = shellObjects.GetAt(i, ref unknownIid);
                JumpItem item = null;
                try
                {
                    item = GetJumpItemForShellObject(unk);
                }
                catch (Exception e)
                {
                    if (e is NullReferenceException || e is SEHException)
                    {
                        throw;
                    }
                }
                retList.Add(new _ShellObjectPair {
                    ShellObject = unk, JumpItem = item
                });
            }
            return(retList);
        }
示例#4
0
        private static List <_ShellObjectPair> GenerateJumpItems(IObjectArray shellObjects)
        {
            Debug.Assert(shellObjects != null);

            var retList = new List <_ShellObjectPair>();

            Guid unknownIid = new Guid(IID.Unknown);
            uint count      = shellObjects.GetCount();

            for (uint i = 0; i < count; ++i)
            {
                // This is potentially a heterogenous list, so get as an IUnknown and QI afterwards.
                object   unk  = shellObjects.GetAt(i, ref unknownIid);
                JumpItem item = null;
                try
                {
                    item = GetJumpItemForShellObject(unk);
                }
                catch (Exception e)
                {
                    if (e is NullReferenceException || e is System.Runtime.InteropServices.SEHException)
                    {
                        throw;
                    }
                    // If we failed the conversion we still want to keep the shell interface for comparision.
                    // Just leave the JumpItem property as null.
                }
                retList.Add(new _ShellObjectPair {
                    ShellObject = unk, JumpItem = item
                });
            }

            return(retList);
        }
示例#5
0
        private static void UnsafeSetWallpaper(string imagePath)
        {
            Guid         currentDesktopId = manager.GetCurrentDesktop(IntPtr.Zero).GetId();
            IObjectArray objectArray      = manager.GetDesktops(IntPtr.Zero);

            for (uint i = 0u; i < objectArray.GetCount(); i++)
            {
                objectArray.GetAt(i, typeof(IVirtualDesktop).GUID, out object virtualDesktop);
                if ((virtualDesktop as IVirtualDesktop).GetId() != currentDesktopId)
                {
                    manager.SetWallpaperPath((IVirtualDesktop)virtualDesktop, imagePath);
                }
            }
        }
示例#6
0
        private IEnumerable ProcessDeletedItems(IObjectArray removedItems)
        {
            uint count;

            removedItems.GetCount(out count);

            if (count == 0)
            {
                return new string[] { }
            }
            ;

            // String array passed to the user via the JumpListItemsRemoved
            // event
            List <string> removedItemsArray = new List <string>();

            // Process each removed item based on it's type
            for (uint i = 0; i < count; i++)
            {
                // Native call to retrieve objects from IObjectArray
                object item;
                removedItems.GetAt(i,
                                   ref TaskbarNativeMethods.IID_IUnknown,
                                   out item);

                // Process item
                if (item is IShellItem)
                {
                    removedItemsArray.Add(RemoveCustomCategoryItem((IShellItem)item));
                }
                else if (item is IShellLinkW)
                {
                    removedItemsArray.Add(RemoveCustomCategoryLink((IShellLinkW)item));
                }
            }

            return(removedItemsArray);
        }
示例#7
0
        private static List<_ShellObjectPair> GenerateJumpItems(IObjectArray shellObjects)
        {
            Debug.Assert(shellObjects != null);

            var retList = new List<_ShellObjectPair>();

            Guid unknownIid = new Guid(IID.Unknown);
            uint count = shellObjects.GetCount();
            for (uint i = 0; i < count; ++i)
            {
                // This is potentially a heterogenous list, so get as an IUnknown and QI afterwards.
                object unk = shellObjects.GetAt(i, ref unknownIid);
                JumpItem item = null;
                try
                {
                    item = GetJumpItemForShellObject(unk);
                }
                catch (Exception e)
                {
                    if (e is NullReferenceException || e is System.Runtime.InteropServices.SEHException)
                    {
                        throw;
                    }
                    // If we failed the conversion we still want to keep the shell interface for comparision.
                    // Just leave the JumpItem property as null.
                }
                retList.Add(new _ShellObjectPair { ShellObject = unk, JumpItem = item });
            }

            return retList;
        }
示例#8
0
        private IEnumerable ProcessDeletedItems(IObjectArray removedItems)
        {
            uint count;
            removedItems.GetCount(out count);

            if (count == 0)
                return new string[] { };

            // String array passed to the user via the JumpListItemsRemoved
            // event
            List<string> removedItemsArray = new List<string>();

            // Process each removed item based on it's type
            for (uint i = 0; i < count; i++)
            {
                // Native call to retrieve objects from IObjectArray
                object item;
                removedItems.GetAt(i,
                    ref TaskbarNativeMethods.IID_IUnknown,
                    out item);

                // Process item
                if (item is IShellItem)
                {
                    removedItemsArray.Add(RemoveCustomCategoryItem((IShellItem)item));
                }
                else if (item is IShellLinkW)
                {
                    removedItemsArray.Add(RemoveCustomCategoryLink((IShellLinkW)item));
                }
            }

            return removedItemsArray;
        }
        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 ShellLink
                {  }

                try
                {
                    IShellItem shellItem = (IShellItem)item;
                    if (shellItem != null)
                    {
                        string path;
                        shellItem.GetDisplayName(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.Cancel)
            {
                _customDestinationList.AbortList();
            }
            return(!args.Cancel);
        }
示例#10
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);
        }
示例#11
0
        private IEnumerable<string> ProcessDeletedItems(IObjectArray removedItems)
        {
            List<string> removedItemsArray = new List<string>();

            uint count;
            removedItems.GetCount(out count);

            // Process each removed item based on its type
            for (uint i = 0; i < count; i++)
            {
                // Native call to retrieve objects from IObjectArray
                object item;
                removedItems.GetAt(i,
                    ref TaskbarNativeMethods.TaskbarGuids.IUnknown,
                    out item);

                IShellItem shellItem = item as IShellItem;
                IShellLinkW shellLink;
                // Process item
                if (shellItem != null)
                {
                    removedItemsArray.Add(RemoveCustomCategoryItem(shellItem));
                }
                else if ((shellLink = item as IShellLinkW) != null)
                {
                    removedItemsArray.Add(RemoveCustomCategoryLink(shellLink));
                }
            }
            return removedItemsArray;
        }