Exemplo n.º 1
0
        public ShellNode(ShellBrowser browser, IntPtr pidl, IntPtr shellFolderPtr)
        {
            this.Browser = browser;

            this.shellFolderPtr = shellFolderPtr;
            this.shellFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(shellFolderPtr, typeof(IShellFolder));
            this.SubFiles = new ShellItemCollection(this);
            this.SubFolders = new ShellItemCollection(this);

            PIDLRel = new Pidl(pidl, false);

            Text = "Desktop";
            Path = "Desktop";

            SetAttributesDesktop(this);

            ShFileInfo info = new ShFileInfo();
            Shell32.SHGetFileInfo(PIDLRel.Ptr, 0, ref info, Marshal.SizeOf(info), SHGFI.Pidl | SHGFI.TypeName | SHGFI.SysIconIndex);

            Type = info.TypeName;

            ShellImageList.SetIconIndex(this, info.IconIndex, false);
            ShellImageList.SetIconIndex(this, info.IconIndex, true);

            SortFlag = 1;
        }
        static ShellImageList()
        {
            ShFileInfo fileInfo = new ShFileInfo();

            SmallImageList = Shell32.SHGetFileInfo(".txt", FileAttribute.Normal, ref fileInfo, Marshal.SizeOf(fileInfo), SHGFI.UseFileAttributes | SHGFI.SysIconIndex | SHGFI.SmallIcon);
            LargeImageList = Shell32.SHGetFileInfo(".txt", FileAttribute.Normal, ref fileInfo, Marshal.SizeOf(fileInfo), SHGFI.UseFileAttributes | SHGFI.SysIconIndex | SHGFI.LargeIcon);
        }
Exemplo n.º 3
0
        public int GetImageIndex()
        {
            ShFileInfo info = new ShFileInfo();
            Shell32.SHGetFileInfo(pidl, 0, ref info, Marshal.SizeOf(info), SHGFI.Pidl | SHGFI.SysIconIndex | SHGFI.OverlayIndex | SHGFI.LargeIcon | SHGFI.AddOverlays | SHGFI.LinkOverlay);
            Shell32.DestroyIcon(info.IconHandle);

            return info.IconIndex;
        }
Exemplo n.º 4
0
        public static int GetSmallAssociatedIconIndex(string path)
        {
            ShFileInfo fileInfo = new ShFileInfo();

            Shell32.SHGetFileInfo(path, 0, ref fileInfo, Marshal.SizeOf(fileInfo), SHGFI.SmallIcon | SHGFI.ShellIconSize | SHGFI.SysIconIndex | SHGFI.LinkOverlay);
            Shell32.DestroyIcon(fileInfo.IconHandle);

            return fileInfo.IconIndex;
        }
Exemplo n.º 5
0
        public static Icon GetLargeAssociatedIcon(string path)
        {
            ShFileInfo fileInfo = new ShFileInfo();
            Shell32.SHGetFileInfo(path, 0, ref fileInfo, Marshal.SizeOf(fileInfo), SHGFI.LargeIcon | SHGFI.Icon | SHGFI.ShellIconSize);

            try
            {
                if (fileInfo.IconHandle != IntPtr.Zero)
                {
                    return Icon.FromHandle(fileInfo.IconHandle);
                }
            }
            finally
            {
                Shell32.DestroyIcon(fileInfo.IconHandle);
            }

            return null;
        }
Exemplo n.º 6
0
        private static void SetInfo(ShellNode item)
        {
            Pidl pidlFull = item.PIDLFull;

            ShFileInfo info = new ShFileInfo();
            Shell32.SHGetFileInfo(pidlFull.Ptr, 0, ref info, Marshal.SizeOf(info), SHGFI.Pidl | SHGFI.TypeName | SHGFI.SysIconIndex);

            pidlFull.Free();

            ShellImageList.SetIconIndex(item, info.IconIndex, false);
            ShellImageList.SetIconIndex(item, info.IconIndex, true);

            item.Type = info.TypeName;
        }
 public static extern IntPtr SHGetFileInfo(string path, FileAttributes fileAttributes, ref ShFileInfo psfi, int fileInfo, SHGFI flags);
 public static extern IntPtr SHGetFileInfo(IntPtr ppidl, FileAttribute dwFileAttributes, ref ShFileInfo sfi, int cbFileInfo, SHGFI uFlags);
 public static extern IntPtr SHGetFileInfo(string pszPath, FileAttribute dwFileAttributes, ref ShFileInfo sfi, int cbFileInfo, SHGFI uFlags);
Exemplo n.º 10
0
        private void Initialize()
        {
            IntPtr tempPidl;
            ShFileInfo info;

            //My Computer
            info = new ShFileInfo();
            tempPidl = IntPtr.Zero;
            Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.Drives, out tempPidl);

            Shell32.SHGetFileInfo(tempPidl, 0, ref info, Marshal.SizeOf(info), SHGFI.Pidl | SHGFI.DisplayName | SHGFI.TypeName);

            SystemFolderName = info.TypeName;
            MyComputerName = info.DisplayName;
            Marshal.FreeCoTaskMem(tempPidl);
            //

            //Dekstop
            tempPidl = IntPtr.Zero;
            Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.Desktop, out tempPidl);
            IntPtr desktopFolderPtr;
            Shell32.SHGetDesktopFolder(out desktopFolderPtr);
            DesktopItem = new ShellNode(this, tempPidl, desktopFolderPtr);
            //


            //My Documents
            uint pchEaten = 0;
            SFGAO pdwAttributes = 0;
            DesktopItem.ShellFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, SpecialFolderPath.MyDocuments, ref pchEaten, out tempPidl, ref pdwAttributes);

            info = new ShFileInfo();
            Shell32.SHGetFileInfo(tempPidl, 0, ref info, Marshal.SizeOf(info), SHGFI.Pidl | SHGFI.DisplayName);

            MyDocumentsName = info.DisplayName;
            Marshal.FreeCoTaskMem(tempPidl);

            StringBuilder path = new StringBuilder(ShellApi.MaxPath);
            Shell32.SHGetFolderPath(IntPtr.Zero, CSIDL.Personal, IntPtr.Zero, SHGFP.TypeCurrent, path);
            MyDocumentsPath = path.ToString();
            //
        }
Exemplo n.º 11
0
        public static int GetLargeAssociatedIconIndex(string path, FileAttributes attributes)
        {
            ShFileInfo fileInfo = new ShFileInfo();

            Shell32.SHGetFileInfo(path, attributes, ref fileInfo, Marshal.SizeOf(fileInfo), SHGFI.LargeIcon | SHGFI.SysIconIndex | SHGFI.ShellIconSize | SHGFI.AddOverlays);
            Shell32.DestroyIcon(fileInfo.IconHandle);

            return fileInfo.IconIndex;
        }
        public static void SetIconIndex(ShellNode item, int index, bool selectedIcon)
        {
            bool hasOverlay = false;
            int result; // The returned Index

            SHGFI flag = SHGFI.SysIconIndex | SHGFI.Pidl | SHGFI.Icon;
            FileAttribute attribute = 0;

            // build Key into HashTable for this Item
            int Key = index * 256;

            if (item.IsLink)
            {
                Key = Key | 1;
                flag = flag | SHGFI.LinkOverlay;
                hasOverlay = true;
            }
            if (item.IsShared)
            {
                Key = Key | 2;
                flag = flag | SHGFI.AddOverlays;
                hasOverlay = true;
            }
            if (selectedIcon)
            {
                Key = Key | 4;
                flag = flag | SHGFI.OpenIcon;
                hasOverlay = true; // not really an overlay, but handled the same
            }

            if (imageTable.ContainsKey(Key))
            {
                result = (int)imageTable[Key];
            }
            else if (!hasOverlay && !item.IsHidden) // for non-overlay icons, we already have
            {
                result = (int)System.Math.Floor((double)Key / 256); // the right index -- put in table
                imageTable[Key] = result;
            }
            else // don't have iconindex for an overlay, get it.
            {
                if (item.IsFileSystem & !item.IsDisk & !item.IsFolder)
                {
                    flag = flag | SHGFI.UseFileAttributes;
                    attribute = attribute | FileAttribute.Normal;
                }

                Pidl pidl = item.PIDLFull;

                ShFileInfo smallFileInfo = new ShFileInfo();
                Shell32.SHGetFileInfo(pidl.Ptr, attribute, ref smallFileInfo, Marshal.SizeOf(smallFileInfo), flag | SHGFI.SmallIcon);

                ShFileInfo largeFileInfo = new ShFileInfo();
                Shell32.SHGetFileInfo(pidl.Ptr, attribute, ref largeFileInfo, Marshal.SizeOf(largeFileInfo), flag | SHGFI.LargeIcon);

                Marshal.FreeCoTaskMem(pidl.Ptr);

                lock (imageTable)
                {
                    result = ComCtl32.ImageList_ReplaceIcon(SmallImageList, -1, smallFileInfo.IconHandle);
                    ComCtl32.ImageList_ReplaceIcon(LargeImageList, -1, largeFileInfo.IconHandle);
                }

                User32.DestroyIcon(smallFileInfo.IconHandle);
                User32.DestroyIcon(largeFileInfo.IconHandle);

                imageTable[Key] = result;
            }

            if (selectedIcon)
            {
                item.SelectedImageIndex = result;
            }
            else
            {
                item.ImageIndex = result;
            }
        }