1

I'm trying to get the icon out of a .lnk file without the .lnk overlay appearing. The documentation has information about a flag SHGFI_ADDOVERLAYS which can be set to add an overlay, but I am looking to remove the overlay.

I have read this question, as well as the links inside of it, but I am still unable to get it working in c#.

Here is the code I have tried:

SHFILEINFO shFileInfo = new SHFILEINFO();

SHGetFileInfo(
    pathToLnk,
    0,
    ref shFileInfo,
    (uint)Marshal.SizeOf(shFileInfo),
    SHGFI_ICON & ~SHGFI_LINKOVERLAY);

As well as some other configurations of the flags.

Thanks in advance for the help.

4

1 回答 1

0

解决方法如下:

[DllImport("Comctl32.dll")]
public static extern IntPtr ImageList_GetIcon(IntPtr himl, int i, uint flags);


SHFILEINFO fileInfo = new SHFILEINFO();
        IntPtr list = SHGetFileInfo(
            pathToLnk,
            FileAttributes,
            ref fileInfo,
            (uint)Marshal.SizeOf(fileInfo),
            SHGFI_SYSICONINDEX);
        var iconHandle = ImageList_GetIcon(list, fileInfo.iIcon.ToInt32(), FileFlags);
        Icon icn = Icon.FromHandle(iconHandle);
于 2017-04-26T12:26:51.500 回答