
Nope, I missed that initially. Thrown by my interpretation of comments
in MSDN (I usually do not have any problem with MSDN docs, presuming
that they cover a given subject).
Anyway, I did get the code working, and got icons to display for
shortcuts, albeit with annoying little tiny arrows. Then found a
variant on the pInvoke'd icon extractor that returns icons without the
arrows. If anyone needs that later:
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x00; // large icon
public const uint SHGFI_SMALLICON = 0x01; // small icon
public const uint SHGFI_SYSICONINDEX = 0x000004000;
public const int ILD_TRANSPARENT = 0x1;
[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};
private static SHFILEINFO shinfo = new SHFILEINFO();
[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(string filePath,
uint dwFileAttributes,
ref SHFILEINFO psfi,
uint cbSizeFileInfo,
uint uFlags);
[DllImport("comctl32.dll", SetLastError = true)]
public static extern IntPtr ImageList_GetIcon(IntPtr himl,
int i, int flags);
public static Icon GetIconWithoutArrow(string filePath)
{
IntPtr PtrIconList = SHGetFileInfo(
filePath, 0,
ref shinfo,
(uint)Marshal.SizeOf(shinfo),
SHGFI_SYSICONINDEX);
IntPtr PtrIcon = ImageList_GetIcon(PtrIconList,
shinfo.iIcon.ToInt32(), ILD_TRANSPARENT);
Icon icon = Icon.FromHandle(PtrIcon);
return icon;
}
(I think that is everything)
In my searches, I did notice some code on CodeProject that put icons
in column headers. I do not need that at the moment though.
Thanks, Jeff.