How to extract full icon from Vista / 7?

If I have a Vista.ico file containing 16x16, 32x32, 256x256 and other versions of the icon, I can successfully download it as a .NET Icon by simply doing -:

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

Then I can access all the images of different sizes in the icon. I can even access 256x256 Vista PNG using the methods described in detail HERE .

However, I did not find a way to get the full set of icon images from the Vista executable. Unfortunately, doing this is:

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

... only leads to the extraction of one 32x32 image. Is there a way to get the whole set of images from an executable file as a .NET icon? Preferably one that also works in XP.

+3
source share
2 answers

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

Hope this helps.

+3
source

try this snippet using the 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]);
+1
source

Source: https://habr.com/ru/post/1730795/


All Articles