通过此代码项目文章和PInvoke.net 上的 ExtractIconEx 演示,您可以编写以下内容:
FileAssociationInfo info = new FileAssociationInfo(".docx");
ProgramAssociationInfo pai = new ProgramAssociationInfo(info.ProgID);
ProgramIcon ico = pai.DefaultIcon;
Icon icoLarge = Martin.Hyldahl.Examples.ExtractIconEx.ExtractIconExample.ExtractIconFromExe(ico.Path, ico.Index, false);
您必须将 ExtractIconFromExe 的签名更改为
public static Icon ExtractIconFromExe(string file, int nIconIndex, bool large)
并将代码更改为几行
if (large)
readIconCount = ExtractIconEx(file, nIconIndex, hIconEx, hDummy, 1);
else
readIconCount = ExtractIconEx(file, nIconIndex, hDummy, hIconEx, 1);