使用的SHGetFileInfo()函数是什么图标,我能找回的最大尺寸是多少? 至于功能状态,我可以得到一个32×32像素的图标(AKA SHGFI_LARGEICON)。 但我试图找出是否有一种方式来获得像一个48×48像素的图标更大。
我发现,有像常数...
public const uint SHGFI_LARGEICON = 0x000000000; // get large icon
public const uint SHGFI_SMALLICON = 0x000000001; // get small icon
public const uint SHIL_JUMBO = 0x000000004; // get jumbo icon 256x256
public const uint SHIL_EXTRALARGE = 0x000000002; // get extra large icon 48x48
public const uint SHIL_LARGE = 0x000000000; // get large icon 32x32
public const uint SHIL_SMALL = 0x000000001; // get small icon 16x16
public const uint SHIL_SYSSMALL = 0x000000003; // get icon based off of GetSystemMetrics
...但我不知道如果这些都是有效的SHGetFileInfo()或没有。 我尝试过了,图标显得模糊和不正确的。 (与您使用的浏览他们不看一样清晰/漂亮如在Windows Explorer中的:中等图标设置)
这是我(注:这是不是一个可行的解决方案的SHIL值不在的SHGetFileInfo()函数记录它只是一些我给的一个镜头。)...
public const uint SHIL_JUMBO = 0x000000004; // get jumbo icon 256x256
public const uint SHIL_EXTRALARGE = 0x000000002; // get extra large icon 48x48
public const uint SHIL_LARGE = 0x000000000; // get large icon 32x32
public const uint SHIL_SMALL = 0x000000001; // get small icon 16x16
public const uint SHIL_SYSSMALL = 0x000000003; // get icon based off of GetSystemMetrics
public const uint SHGFI_ICON = 0x000000100; // get icon
public const uint SHGFI_OPENICON = 0x000000002; // get open icon
[DllImport("Shell32.dll")]
public static extern IntPtr SHGetFileInfo(
IntPtr pszPath,
uint dwFileAttributes,
ref SHFILEINFO psfi,
uint cbFileInfo,
uint uFlags
);
[DllImport("User32.dll")]
public static extern int DestroyIcon(IntPtr hIcon);
public struct SHFILEINFO
{
public const int NAMESIZE = 80;
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NAMESIZE)]
public string szTypeName;
}
public enum IconSize
{
Jumbo = 4, //256x256
ExtraLarge = 2, //48x48
Large = 0, //32x32
Small = 1 //16x16
}
IconSize size = IconSize.ExtraLarge;
uint flags = SHGFI_ICON;
flags |= SHGFI_OPENICON;
switch (size)
{
case IconSize.Small:
flags |= SHIL_SMALL;
break;
case IconSize.Large:
flags |= SHIL_LARGE;
break;
case IconSize.ExtraLarge:
flags |= SHIL_EXTRALARGE;
break;
case IconSize.Jumbo:
flags |= SHIL_JUMBO;
break;
}
//Get me a PDIL to the My Documents folder (this is done with a LOT of other
//code but I know for a fact it returns the name, path, and PDIL correctly!
CGFolder cFolder = new CGFolder(Environment.SpecialFolder.MyDocuments);
string sName = cFolder.Pidl.DisplayName;
string sPath = cFolder.Pidl.PhysicalPath;
IntPtr ptrPDIL = cFolder.Pidl.Pidl;
SHFILEINFO shfi = new SHFILEINFO();
SHGetFileInfo(ptrPDIL, 0, ref shfi, (uint)Marshal.SizeOf(shfi), flags);
if (shfi.hIcon == IntPtr.Zero) return null;
icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
DestroyIcon(shfi.hIcon);
return icon;
参考文献:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762179%28v=vs.85%29.aspx )