Exemplo n.º 1
0
        /// <summary>
        /// Gibt das große Icon des Pfades aus
        /// </summary>
        /// <param name="pfad">Der Pfad zu einem Ordner oder Datei</param>
        /// <returns></returns>
        public static Icon GetLargeIcon(string pfad)
        {
            IntPtr hImgSmall = default(IntPtr);

            //The handle to the system image list.
            WinAPI.SHFILEINFO shinfo = new WinAPI.SHFILEINFO();
            shinfo.szDisplayName = new string((char)0, 260);
            shinfo.szTypeName    = new string((char)0, 80);
            hImgSmall            = WinAPI.SHGetFileInfo(pfad, 0, ref shinfo, Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_LARGEICON);
            System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
            return(myIcon);
        }
Exemplo n.º 2
0
        public NativeDirectoryInfo(WinAPI.CSIDL type = WinAPI.CSIDL.CSIDL_DRIVES)
        {
            // new ShellItem() can only be called once.
            if (haveRootShell)
            {
                throw new Exception("The Desktop shell item already exists so cannot be created again.");
            }

            // Obtain the root IShellFolder interface.
            int hRes = WinAPI.SHGetDesktopFolder(ref _desktopShellFolder);

            if (hRes != 0)
            {
                Marshal.ThrowExceptionForHR(hRes);
            }

            // Now get the PIDL for the Desktop shell item.
            hRes = WinAPI.SHGetSpecialFolderLocation(IntPtr.Zero, type, ref _pIDL);

            if (hRes != 0)
            {
                Marshal.ThrowExceptionForHR(hRes);
            }

            if (type != WinAPI.CSIDL.CSIDL_DESKTOP)
            {
                hRes = (int)_desktopShellFolder.BindToObject(_pIDL, IntPtr.Zero, ref WinAPI.IID_IShellFolder,
                                                             out _shellFolder);
                _rootShellFolder = ShellFolder;
            }
            else
            {
                _rootShellFolder = DesktopShellFolder;
                _shellFolder     = DesktopShellFolder;
            }

            if (hRes != 0)
            {
                Marshal.ThrowExceptionForHR(hRes);
            }

            // Now retrieve some attributes for the root shell item.
            shInfo = new WinAPI.SHFILEINFO();
            WinAPI.SHGetFileInfo(_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo), vFlags);

            // Set the arributes to object properties.
            DisplayName   = shInfo.szDisplayName;
            IconIndex     = shInfo.iIcon;
            IsFolder      = true;
            haveRootShell = true;
        }
Exemplo n.º 3
0
        public NativeDirectoryInfo(IntPtr pIDL, NativeDirectoryInfo shParent)
        {
            Parent = shParent;
            // We need the Desktop shell item to exist first.
            if (haveRootShell == false)
            {
                throw new Exception("The root shell item must be created before creating a sub-item");
            }

            // Create the FQ PIDL for this new item.
            _pIDL = WinAPI.ILCombine(shParent.PIDL, pIDL);

            // Get the properties of this item.
            WinAPI.SFGAOF uFlags = WinAPI.SFGAOF.SFGAO_FOLDER | WinAPI.SFGAOF.SFGAO_HASSUBFOLDER;

            // Here we get some basic attributes.
            DesktopShellFolder.GetAttributesOf(1, out _pIDL, out uFlags);
            IsFolder = Convert.ToBoolean(uFlags & WinAPI.SFGAOF.SFGAO_FOLDER);
            // bug not working
            HasSubFolder = Convert.ToBoolean(uFlags & WinAPI.SFGAOF.SFGAO_HASSUBFOLDER);
            // Now we want to get extended attributes such as the icon index etc.
            shInfo = new WinAPI.SHFILEINFO();
            WinAPI.SHGetFileInfo(_pIDL, WinAPI.FILE_ATTRIBUTE_NORMAL, out shInfo, (uint)Marshal.SizeOf(shInfo), vFlags);
            DisplayName = shInfo.szDisplayName;
            TypeName    = shInfo.szTypeName;
            IconIndex   = shInfo.iIcon;

            // Create the IShellFolder interface for this item.
            if (IsFolder)
            {
                uint hRes = shParent._shellFolder.BindToObject(pIDL, IntPtr.Zero, ref WinAPI.IID_IShellFolder,
                                                               out _shellFolder);
                if (hRes != 0)
                {
                    Marshal.ThrowExceptionForHR((int)hRes);
                }
            }
        }
Exemplo n.º 4
0
 public NativeFileInfo(string path)
 {
     Path   = path;
     shInfo = new WinAPI.SHFILEINFO();
     WinAPI.SHGetFileInfo(path, WinAPI.FILE_ATTRIBUTE_NORMAL, out shInfo, (uint)Marshal.SizeOf(shInfo), vFlags);
 }