using System;
using System.Collections;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
namespace TOA.Common
{
/// <summary>
/// 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, //指定的文件名
FILE_ATTRIBUTE dwFileAttributes, //文件屬性
ref SHFILEINFO sfi, //返回獲得的文件信息,是一個記錄類型
int cbFileInfo, //文件的類型名
SHGFI uFlags);
#endregion
#region STRUCTS
// Contains information about a file object
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
private struct SHFILEINFO
{
public IntPtr hIcon; //文件的圖標句柄
public IntPtr iIcon; //圖標的系統索引號
public uint dwAttributes; //文件的屬性值
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName; //文件的顯示名
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName; //文件的類型名
};
#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, //獲得屬性
DISPLAYNAME = 0x200, //獲得顯示名
EXETYPE = 0x2000,
ICON = 0x100, //獲得圖標
ICONLOCATION = 0x1000,
LARGEICON = 0, //獲得大圖標
LINKOVERLAY = 0x8000,
OPENICON = 2,
OVERLAYINDEX = 0x40,
PIDL = 8,
SELECTED = 0x10000,
SHELLICONSIZE = 4,
SMALLICON = 1, //獲得小圖標
SYSICONINDEX = 0x4000,
TYPENAME = 0x400, //獲得類型名
USEFILEATTRIBUTES = 0x10
}
// Flags that specify the file information to retrieve with SHGetFileInfo
[Flags]
public enum FILE_ATTRIBUTE
{
READONLY = 0x00000001,
HIDDEN = 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
//保存小圖標列表
private static System.Windows.Forms.ImageList smallImageList;
//保存大圖標列表
private static System.Windows.Forms.ImageList largeImageList;
static ShellImages()
{
smallImageList = new System.Windows.Forms.ImageList();
largeImageList = new System.Win