Changeset 850 for branches/eraser6/Util/File.cs
- Timestamp:
- 1/5/2009 9:37:55 AM (3 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Util/File.cs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Util/File.cs
r810 r850 33 33 namespace Eraser.Util 34 34 { 35 using HICON = IntPtr;36 using HIMAGELIST = IntPtr;37 38 35 public static class File 39 36 { … … 105 102 public static string GetFileDescription(string path) 106 103 { 107 S HFILEINFO shfi = newSHFILEINFO();108 S HGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi),109 S HGetFileInfoFlags.SHGFI_DISPLAYNAME);104 ShellAPI.SHFILEINFO shfi = new ShellAPI.SHFILEINFO(); 105 ShellAPI.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), 106 ShellAPI.SHGetFileInfoFlags.SHGFI_DISPLAYNAME); 110 107 return shfi.szDisplayName; 111 108 } … … 121 118 public static Icon GetFileIcon(string path) 122 119 { 123 S HFILEINFO shfi = newSHFILEINFO();124 S HGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi),125 S HGetFileInfoFlags.SHGFI_SMALLICON |SHGetFileInfoFlags.SHGFI_ICON);120 ShellAPI.SHFILEINFO shfi = new ShellAPI.SHFILEINFO(); 121 ShellAPI.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), 122 ShellAPI.SHGetFileInfoFlags.SHGFI_SMALLICON | ShellAPI.SHGetFileInfoFlags.SHGFI_ICON); 126 123 127 124 if (shfi.hIcon != IntPtr.Zero) … … 234 231 sizeof(ushort), IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero); 235 232 } 236 }237 238 /// <summary>239 /// Retrieves information about an object in the file system, such as a240 /// file, folder, directory, or drive root.241 /// </summary>242 /// <param name="path">[in] A pointer to a null-terminated string of maximum243 /// length MAX_PATH that contains the path and file name. Both absolute244 /// and relative paths are valid.245 ///246 /// If the uFlags parameter includes the SHGFI_PIDL flag, this parameter247 /// must be the address of an ITEMIDLIST (PIDL) structure that contains248 /// the list of item identifiers that uniquely identifies the file within249 /// the Shell's namespace. The pointer to an item identifier list (PIDL)250 /// must be a fully qualified PIDL. Relative PIDLs are not allowed.251 ///252 /// If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag,253 /// this parameter does not have to be a valid file name. The function254 /// will proceed as if the file exists with the specified name and with255 /// the file attributes passed in the dwFileAttributes parameter. This256 /// allows you to obtain information about a file type by passing just257 /// the extension for pszPath and passing FILE_ATTRIBUTE_NORMAL in258 /// dwFileAttributes.259 ///260 /// This string can use either short (the 8.3 form) or long file names.</param>261 /// <param name="fileAttributes">[in] A combination of one or more file262 /// attribute flags (FILE_ATTRIBUTE_ values as defined in Winnt.h). If263 /// uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this264 /// parameter is ignored.</param>265 /// <param name="psfi">[out] The address of a SHFILEINFO structure to266 /// receive the file information.</param>267 /// <param name="cbFileInfo">[in] The size, in bytes, of the SHFILEINFO268 /// structure pointed to by the psfi parameter.</param>269 /// <param name="uFlags">[in] The flags that specify the file information to retrieve.270 /// This parameter can be a combination of the values in SHGetFileInfoFlags</param>271 /// <returns>Returns a value whose meaning depends on the uFlags parameter.272 ///273 /// If uFlags does not contain SHGFI_EXETYPE or SHGFI_SYSICONINDEX, the return274 /// value is nonzero if successful, or zero otherwise.275 ///276 /// If uFlags contains the SHGFI_EXETYPE flag, the return value specifies277 /// the type of the executable file. It will be one of the following values.278 /// 0 Nonexecutable file or an error condition.279 /// LOWORD = NE or PE and HIWORD = Windows version Microsoft Windows application.280 /// LOWORD = MZ and HIWORD = 0 Windows 95, Windows 98: Microsoft MS-DOS .exe, .com, or .bat file281 /// Microsoft Windows NT, Windows 2000, Windows XP: MS-DOS .exe or .com file282 /// LOWORD = PE and HIWORD = 0 Windows 95, Windows 98: Microsoft Win32 console application283 /// Windows NT, Windows 2000, Windows XP: Win32 console application or .bat file284 /// </returns>285 [DllImport("Shell32.dll", CharSet = CharSet.Unicode)]286 private static extern IntPtr SHGetFileInfo(string path, uint fileAttributes,287 ref SHFILEINFO psfi, int fileInfo, SHGetFileInfoFlags flags);288 289 enum SHGetFileInfoFlags290 {291 /// <summary>292 /// Retrieve the handle to the icon that represents the file and the293 /// index of the icon within the system image list. The handle is294 /// copied to the hIcon member of the structure specified by psfi,295 /// and the index is copied to the iIcon member.296 /// </summary>297 SHGFI_ICON = 0x000000100,298 299 /// <summary>300 /// Retrieve the display name for the file. The name is copied to the301 /// szDisplayName member of the structure specified in psfi. The returned302 /// display name uses the long file name, if there is one, rather than303 /// the 8.3 form of the file name.304 /// </summary>305 SHGFI_DISPLAYNAME = 0x000000200,306 307 /// <summary>308 /// Retrieve the string that describes the file's type. The string309 /// is copied to the szTypeName member of the structure specified in310 /// psfi.311 /// </summary>312 SHGFI_TYPENAME = 0x000000400,313 314 /// <summary>315 /// Retrieve the item attributes. The attributes are copied to the316 /// dwAttributes member of the structure specified in the psfi parameter.317 /// These are the same attributes that are obtained from318 /// IShellFolder::GetAttributesOf.319 /// </summary>320 SHGFI_ATTRIBUTES = 0x000000800,321 322 /// <summary>323 /// Retrieve the name of the file that contains the icon representing324 /// the file specified by pszPath, as returned by the325 /// IExtractIcon::GetIconLocation method of the file's icon handler.326 /// Also retrieve the icon index within that file. The name of the327 /// file containing the icon is copied to the szDisplayName member328 /// of the structure specified by psfi. The icon's index is copied to329 /// that structure's iIcon member.330 /// </summary>331 SHGFI_ICONLOCATION = 0x000001000,332 333 /// <summary>334 /// Retrieve the type of the executable file if pszPath identifies an335 /// executable file. The information is packed into the return value.336 /// This flag cannot be specified with any other flags.337 /// </summary>338 SHGFI_EXETYPE = 0x000002000,339 340 /// <summary>341 /// Retrieve the index of a system image list icon. If successful,342 /// the index is copied to the iIcon member of psfi. The return value343 /// is a handle to the system image list. Only those images whose344 /// indices are successfully copied to iIcon are valid. Attempting345 /// to access other images in the system image list will result in346 /// undefined behavior.347 /// </summary>348 SHGFI_SYSICONINDEX = 0x000004000,349 350 /// <summary>351 /// Modify SHGFI_ICON, causing the function to add the link overlay352 /// to the file's icon. The SHGFI_ICON flag must also be set.353 /// </summary>354 SHGFI_LINKOVERLAY = 0x000008000,355 356 /// <summary>357 /// Modify SHGFI_ICON, causing the function to blend the file's icon358 /// with the system highlight color. The SHGFI_ICON flag must also359 /// be set.360 /// </summary>361 SHGFI_SELECTED = 0x000010000,362 363 /// <summary>364 /// Modify SHGFI_ATTRIBUTES to indicate that the dwAttributes member365 /// of the SHFILEINFO structure at psfi contains the specific attributes366 /// that are desired. These attributes are passed to IShellFolder::GetAttributesOf.367 /// If this flag is not specified, 0xFFFFFFFF is passed to368 /// IShellFolder::GetAttributesOf, requesting all attributes. This flag369 /// cannot be specified with the SHGFI_ICON flag.370 /// </summary>371 SHGFI_ATTR_SPECIFIED = 0x000020000,372 373 /// <summary>374 /// Modify SHGFI_ICON, causing the function to retrieve the file's375 /// large icon. The SHGFI_ICON flag must also be set.376 /// </summary>377 SHGFI_LARGEICON = 0x000000000,378 379 /// <summary>380 /// Modify SHGFI_ICON, causing the function to retrieve the file's381 /// small icon. Also used to modify SHGFI_SYSICONINDEX, causing the382 /// function to return the handle to the system image list that383 /// contains small icon images. The SHGFI_ICON and/or384 /// SHGFI_SYSICONINDEX flag must also be set.385 /// </summary>386 SHGFI_SMALLICON = 0x000000001,387 388 /// <summary>389 /// Modify SHGFI_ICON, causing the function to retrieve the file's390 /// open icon. Also used to modify SHGFI_SYSICONINDEX, causing the391 /// function to return the handle to the system image list that392 /// contains the file's small open icon. A container object displays393 /// an open icon to indicate that the container is open. The SHGFI_ICON394 /// and/or SHGFI_SYSICONINDEX flag must also be set.395 /// </summary>396 SHGFI_OPENICON = 0x000000002,397 398 /// <summary>399 /// Modify SHGFI_ICON, causing the function to retrieve a Shell-sized400 /// icon. If this flag is not specified the function sizes the icon401 /// according to the system metric values. The SHGFI_ICON flag must402 /// also be set.403 /// </summary>404 SHGFI_SHELLICONSIZE = 0x000000004,405 406 /// <summary>407 /// Indicate that pszPath is the address of an ITEMIDLIST structure408 /// rather than a path name.409 /// </summary>410 SHGFI_PIDL = 0x000000008,411 412 /// <summary>413 /// Indicates that the function should not attempt to access the file414 /// specified by pszPath. Rather, it should act as if the file specified415 /// by pszPath exists with the file attributes passed in dwFileAttributes.416 /// This flag cannot be combined with the SHGFI_ATTRIBUTES, SHGFI_EXETYPE,417 /// or SHGFI_PIDL flags.418 /// </summary>419 SHGFI_USEFILEATTRIBUTES = 0x000000010,420 421 /// <summary>422 /// Version 5.0. Apply the appropriate overlays to the file's icon.423 /// The SHGFI_ICON flag must also be set.424 /// </summary>425 SHGFI_ADDOVERLAYS = 0x000000020,426 427 /// <summary>428 /// Version 5.0. Return the index of the overlay icon. The value of429 /// the overlay index is returned in the upper eight bits of the iIcon430 /// member of the structure specified by psfi. This flag requires that431 /// the SHGFI_ICON be set as well.432 /// </summary>433 SHGFI_OVERLAYINDEX = 0x000000040434 }435 436 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]437 private struct SHFILEINFO438 {439 /// <summary>440 /// A handle to the icon that represents the file. You are responsible441 /// for destroying this handle with DestroyIcon when you no longer need it.442 /// </summary>443 public HICON hIcon;444 445 /// <summary>446 /// The index of the icon image within the system image list.447 /// </summary>448 public int iIcon;449 450 /// <summary>451 /// An array of values that indicates the attributes of the file object.452 /// For information about these values, see the IShellFolder::GetAttributesOf453 /// method.454 /// </summary>455 public uint dwAttributes;456 457 /// <summary>458 /// A string that contains the name of the file as it appears in the459 /// Microsoft Windows Shell, or the path and file name of the file460 /// that contains the icon representing the file.461 /// </summary>462 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]463 public string szDisplayName;464 465 /// <summary>466 /// A string that describes the type of file.467 /// </summary>468 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]469 public string szTypeName;470 233 } 471 234
Note: See TracChangeset
for help on using the changeset viewer.
