Esempio n. 1
0
        /// <summary>
        /// Creates the SystemImageList
        /// </summary>
        private void create()
        {
            // forget last image list if any:
            hIml = IntPtr.Zero;

            if (isXpOrAbove())
            {
                // Get the System IImageList object from the Shell:
                Guid iidImageList = new
                                    Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");
                int ret = SHGetImageList(
                    (int)size,
                    ref iidImageList,
                    ref iImageList
                    );
                // the image list handle is the IUnknown pointer, but
                // using Marshal.GetIUnknownForObject doesn't return
                // the right value.  It really doesn't hurt to make
                // a second call to get the handle:
                SHGetImageListHandle((int)size, ref iidImageList, ref hIml);
            }
            else
            {
                // Prepare flags:
                var dwFlags = FIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES | FIcon.SHGetFileInfoConstants.SHGFI_SYSICONINDEX;
                if (size == SysImageListSize.smallIcons)
                {
                    dwFlags |= FIcon.SHGetFileInfoConstants.SHGFI_SMALLICON;
                }
                // Get image list
                var  shfi     = new BExplorer.Shell.Interop.SHFILEINFO();
                uint shfiSize = (uint)Marshal.SizeOf(shfi.GetType());

                // Call SHGetFileInfo to get the image list handle
                // using an arbitrary file:
                hIml = SHGetFileInfo(
                    ".txt",
                    FILE_ATTRIBUTE_NORMAL,
                    ref shfi,
                    shfiSize,
                    (uint)dwFlags);
                System.Diagnostics.Debug.Assert((hIml != IntPtr.Zero), "Failed tocreate Image List<>");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the index of the icon for the specified file
        /// </summary>
        /// <param name="fileName">Filename to get icon for</param>
        /// <param name="forceLoadFromDisk">If True, then hit the disk to get the
        /// icon,
        /// otherwise only hit the disk if no cached icon is available.</param>
        /// <param name="iconState">Flags specifying the state of the icon
        /// returned.</param>
        /// <returns>Index of the icon</returns>
        public int IconIndex(string fileName, bool forceLoadFromDisk, ShellIconStateConstants iconState)
        {
            FIcon.SHGetFileInfoConstants dwFlags = FIcon.SHGetFileInfoConstants.SHGFI_SYSICONINDEX;
            int dwAttr = 0;

            if (size == SysImageListSize.smallIcons)
            {
                dwFlags |= FIcon.SHGetFileInfoConstants.SHGFI_SMALLICON;
            }

            // We can choose whether to access the disk or not. If you don't
            // hit the disk, you may get the wrong icon if the icon is
            // not cached. Also only works for files.
            if (!forceLoadFromDisk)
            {
                dwFlags |= FIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES;
                dwAttr   = FILE_ATTRIBUTE_NORMAL;
            }
            else
            {
                dwAttr = 0;
            }

            // sFileSpec can be any file. You can specify a
            // file that does not exist and still get the
            // icon, for example sFileSpec = "C:\PANTS.DOC"
            var    shfi     = new BExplorer.Shell.Interop.SHFILEINFO();
            uint   shfiSize = (uint)Marshal.SizeOf(shfi.GetType());
            IntPtr retVal   = SHGetFileInfo(
                fileName, dwAttr, ref shfi, shfiSize,
                ((uint)(dwFlags) | (uint)iconState));

            if (retVal.Equals(IntPtr.Zero))
            {
                System.Diagnostics.Debug.Assert((!retVal.Equals(IntPtr.Zero)), "Failed to get icon index");
                return(0);
            }
            else
            {
                return(shfi.iIcon);
            }
        }
Esempio n. 3
0
		/// <summary>
		/// Creates the SystemImageList
		/// </summary>
		private void create() {
			// forget last image list if any:
			hIml = IntPtr.Zero;

			if (isXpOrAbove()) {
				// Get the System IImageList object from the Shell:
				Guid iidImageList = new
				 Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");
				int ret = SHGetImageList(
				   (int)size,
				   ref iidImageList,
				   ref iImageList
				   );
				// the image list handle is the IUnknown pointer, but
				// using Marshal.GetIUnknownForObject doesn't return
				// the right value.  It really doesn't hurt to make
				// a second call to get the handle:
				SHGetImageListHandle((int)size, ref iidImageList, ref hIml);
			}
			else {
				// Prepare flags:
				var dwFlags = FIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES | FIcon.SHGetFileInfoConstants.SHGFI_SYSICONINDEX;
				if (size == SysImageListSize.smallIcons) {
					dwFlags |= FIcon.SHGetFileInfoConstants.SHGFI_SMALLICON;
				}
				// Get image list
				var shfi = new BExplorer.Shell.Interop.SHFILEINFO();
				uint shfiSize = (uint)Marshal.SizeOf(shfi.GetType());

				// Call SHGetFileInfo to get the image list handle
				// using an arbitrary file:
				hIml = SHGetFileInfo(
				   ".txt",
				   FILE_ATTRIBUTE_NORMAL,
				   ref shfi,
				   shfiSize,
				   (uint)dwFlags);
				System.Diagnostics.Debug.Assert((hIml != IntPtr.Zero), "Failed tocreate Image List<>");
			}
		}
Esempio n. 4
0
		/// <summary>
		/// Returns the index of the icon for the specified file
		/// </summary>
		/// <param name="fileName">Filename to get icon for</param>
		/// <param name="forceLoadFromDisk">If True, then hit the disk to get the
		/// icon,
		/// otherwise only hit the disk if no cached icon is available.</param>
		/// <param name="iconState">Flags specifying the state of the icon
		/// returned.</param>
		/// <returns>Index of the icon</returns>
		public int IconIndex(string fileName, bool forceLoadFromDisk, ShellIconStateConstants iconState) {
			FIcon.SHGetFileInfoConstants dwFlags = FIcon.SHGetFileInfoConstants.SHGFI_SYSICONINDEX;
			int dwAttr = 0;
			if (size == SysImageListSize.smallIcons) {
				dwFlags |= FIcon.SHGetFileInfoConstants.SHGFI_SMALLICON;
			}

			// We can choose whether to access the disk or not. If you don't
			// hit the disk, you may get the wrong icon if the icon is
			// not cached. Also only works for files.
			if (!forceLoadFromDisk) {
				dwFlags |= FIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES;
				dwAttr = FILE_ATTRIBUTE_NORMAL;
			}
			else {
				dwAttr = 0;
			}

			// sFileSpec can be any file. You can specify a
			// file that does not exist and still get the
			// icon, for example sFileSpec = "C:\PANTS.DOC"
			var shfi = new BExplorer.Shell.Interop.SHFILEINFO();
			uint shfiSize = (uint)Marshal.SizeOf(shfi.GetType());
			IntPtr retVal = SHGetFileInfo(
			   fileName, dwAttr, ref shfi, shfiSize,
			   ((uint)(dwFlags) | (uint)iconState));

			if (retVal.Equals(IntPtr.Zero)) {
				System.Diagnostics.Debug.Assert((!retVal.Equals(IntPtr.Zero)), "Failed to get icon index");
				return 0;
			}
			else {
				return shfi.iIcon;
			}
		}
Esempio n. 5
0
 private static extern IntPtr SHGetFileInfo(
     string pszPath,
     int dwFileAttributes,
     ref BExplorer.Shell.Interop.SHFILEINFO psfi,
     uint cbFileInfo,
     uint uFlags);