How Do I Extract a Full Icon From a Vista/7 Executable?

时光毁灭记忆、已成空白 提交于 2019-12-13 14:43:26

问题


If I have a Vista .ico file which contains a 16x16, 32x32, 256x256 etc. version of an icon, I can successfully load it as a .NET Icon by simply doing -:

Icon myIcon = new Icon("C:\\MyIcon.ico");

I can then access all of the various sized images in the icon. I can even access the 256x256 Vista PNG using methods detailed HERE.

However, I haven't found a way to get the full set of icon images from a Vista executable. Unfortunately, doing this -:

Icon myIcon = Icon.ExtractAssociatedIcon("C:\\MyExe.exe");

...only results in a single 32x32 image being extracted. Is there a way get the entire set of images from an executable as a .NET Icon? Preferably one that also works in XP.


回答1:


Have a look at this article 'IconLib' on CodeProject. Also, look at this version using the 'ExtractIconExA' API via pinvoke in VB.NET.

Hope this helps.




回答2:


try this snippet with PrivateExtractIcons API:

[DllImport("User32.dll", CharSet = CharSet.Auto)]
      internal static extern UInt32 PrivateExtractIcons(String lpszFile, int nIconIndex, int cxIcon, int cyIcon, IntPtr[] phicon, IntPtr[] piconid, UInt32 nIcons, UInt32 flags);

IntPtr[] phicon = new IntPtr[] { IntPtr.Zero };
IntPtr[] piconid = new IntPtr[] { IntPtr.Zero };

PrivateExtractIcons(path, 0, cx, cy, phicon, piconid, 1, 0);

if (phicon[0] != IntPtr.Zero)
    return System.Drawing.Icon.FromHandle(phicon[0]);


来源:https://stackoverflow.com/questions/2173736/how-do-i-extract-a-full-icon-from-a-vista-7-executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!