![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public class SysIO2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public SysIO2()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
private const uint SHGFI_ICON = 0x100;
private const uint SHGFI_LARGEICON = 0x0;
private const uint SHGFI_SMALLICON = 0x1;
public const uint SHGFI_USEFILEATTRIBUTES = 0x10;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
[DllImport("kernel32.dll")]
internal static extern void ExitProcess(int a);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
[DllImport("shell32.dll")]
private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
[StructLayout(LayoutKind.Sequential)]
private struct SHFILEINFO
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 获取指定文件(或者扩展名)和系统关联的小图标
/// </summary>
/// <param name="strExtension">文件名,或者文件扩展名(.bmp等等)</param>
/// <returns></returns>
internal static Icon GetSmallIcon(string strExtension)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string strFileName = Path.GetExtension(strExtension);
if (strFileName == "")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
strFileName = strExtension;
}
IntPtr hImgSmall;
SHFILEINFO shinfo = new SHFILEINFO();
hImgSmall = SHGetFileInfo(strFileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
return myIcon;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 获取指定文件(或者扩展名)和系统关联的大图标
/// </summary>
/// <param name="strExtension">文件名,或者文件扩展名(.bmp等等)</param>
/// <returns></returns>
internal static Icon GetLargeIcon(string strExtension)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string strFileName = Path.GetExtension(strExtension);
if (strFileName == "")
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
strFileName = strExtension;
}
IntPtr hImgLarge;
SHFILEINFO shinfo = new SHFILEINFO();
hImgLarge = SHGetFileInfo(strFileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES);
Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
return myIcon;
}
}
posted @
2007-01-22 17:00
轮回
阅读(
563)
评论()
编辑
收藏
举报