从SHGetFileInfo()返回的图标的最大大小是多少? [英] What is the Maximum Size Of An Icon Returned From SHGetFileInfo()?

查看:680
本文介绍了从SHGetFileInfo()返回的图标的最大大小是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SHGetFileInfo()函数,我可以获取的图标的最大大小是多少?就功能状态而言,我可以获得一个32x32像素图标(AKA SHGFI_LARGEICON)。但是我试图弄清楚是否有办法获得更大的东西,比如一个48x48像素的图标。

Using the SHGetFileInfo() function what is the maximum size of an icon that I can get back? As far as the function states I can get back a 32x32 pixel icon (AKA SHGFI_LARGEICON). But I was trying to figure out if there was a way to get something larger like a 48x48 pixel icon.

我发现有一些常数如...

I found that there are constants like...

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()与否。我试了一下,图标看起来很模糊,不对。 (使用View:Medium Icons设置时,它们看起来不像Windows资源管理器中那样清晰/漂亮)

... but I'm not sure if those are valid for SHGetFileInfo() or not. I tried it and the icons seem blurry and not right. (They do not look as clear/nice as the ones in Windows Explorer with you use the View: Medium Icons setting)

这就是我所拥有的(注意:这是不是一个有效的解决方案,SHIL值没有在SHGetFileInfo()函数中记录。这只是我在拍摄的东西。)...

This is what I have (NOTE: This is not a working solution the SHIL values are not documented in the SHGetFileInfo() function. It was just something I was giving a shot at.)...

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

推荐答案

系统映像列表中的索引对于所有图标大小都是相同的,因此使用 SHGetFileInfo 获取索引 SHGFI_SYSICONINDEX 标志,并使用 imagelist API 从超大或巨型图像列表中提取它,您可以从 SHGetImageList function。

The index in the system image list is the same for all icon sizes, so get the index using SHGetFileInfo with the SHGFI_SYSICONINDEX flag, and use the imagelist API to extract it from the "extra-large" or "jumbo" image lists which you can get from the SHGetImageList function.

SHGetFileInfo 本身只能返回小(例如16x16)和大(例如32x32)HICON。

SHGetFileInfo itself can only return small (e.g. 16x16) and large (e.g. 32x32) HICONs.

这篇关于从SHGetFileInfo()返回的图标的最大大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆