Using System;
Using System. Collections;
Using System. Text;
Using System. Runtime. InteropServices;
Using System. Drawing;
Namespace TOA. Common
{
/// <Summary>
/// Summary of GetIcon.
/// </Summary>
Public class ShellImages
{
# Region DLLIMPORT
// Retrieves information about an object in the file system,
// Such as a file, a folder, a directory, or a drive root.
[DllImport ("shell32 ",
EntryPoint = "SHGetFileInfo ",
ExactSpelling = false,
CharSet = CharSet. Auto,
SetLastError = true)]
Private static extern IntPtr SHGetFileInfo (
String pszPath, // Specify the file name
FILE_ATTRIBUTE dwFileAttributes,// File attributes
Ref SHFILEINFO sfi, // Return the obtained file information, which is a record type
Int cbFileInfo, // File type name
SHGFI uFlags );
# Endregion
# Region STRUCTS
// Contains information about a file object
[StructLayout (LayoutKind. Sequential, CharSet = CharSet. Auto)]
Private struct SHFILEINFO
{
Public IntPtr hIcon; // File icon handle
Public IntPtr iIcon; // System index number of the icon
Public uint dwAttributes; // File property value
[Financialas (UnmanagedType. ByValTStr, SizeConst = 260)]
Public string szDisplayName; // File display name
[Financialas (UnmanagedType. ByValTStr, SizeConst = 80)]
Public string szTypeName; // File type name
};
# Endregion
# Region Enums
// Flags that specify the file information to retrieve with SHGetFileInfo
[Flags]
Public enum SHGFI: uint
{
ADDOVERLAYS = 0x20,
ATTR_SPECIFIED = 0x20000,
ATTRIBUTES = 0x800, // Obtain attributes
DISPLAYNAME = 0x200, // Obtain the display name
EXETYPE = 0x2000,
ICON = 0x100, // Get the icon
ICONLOCATION = 0x1000,
LARGEICON = 0, // Get the big icon
LINKOVERLAY = 0x8000,
OPENICON = 2,
OVERLAYINDEX = 0x40,
PIDL = 8,
SELECTED = 0x10000,
SHELLICONSIZE = 4,
SMALLICON = 1, // Obtain the small icon
SYSICONINDEX = 0x4000,
TYPENAME = 0x400, // Obtain the type name
USEFILEATTRIBUTES = 0x10
}
// Flags that specify the file information to retrieve with SHGetFileInfo
[Flags]
Public enum FILE_ATTRIBUTE
{
READONLY = 0x00000001,
Hiding = 0x00000002,
SYSTEM = 0x00000004,
DIRECTORY = 0x00000010,
ARCHIVE = 0x00000020,
DEVICE = 0x00000040,
NORMAL = 0x00000080,
TEMPORARY = 0x00000100,
SPARSE_FILE = 0x00000200,
REPARSE_POINT = 0x00000400,
COMPRESSED = 0x00000800,
OFFLINE = 0x00001000,
NOT_CONTENT_INDEXED = 0x00002000,
ENCRYPTED = 0x00004000
}
# Endregion
# Region Variables
// Save the small icon list
Private static System. Windows. Forms. ImageList smallImageList;
// Save the large icon list
Private static System. Windows. Forms. ImageList largeImageList;
Static ShellImages ()
{
SmallImageList = new System. Windows. Forms. ImageList ();
LargeImageList = new System. Win