Bonjour.
Je cherche à afficher des icônes associés aux fichiers déporté sur mon application par "drag and drop", mais par la méthode
ExtractAssociatedIcon(file);
, je ne peux récupérer qu'une image 32x32px. Or cela m'est insuffisant.
J'ai bien trouvé un sujet https://www.developpez.net/forums/d8...one-d-fichier/ qui propose la méthode de https://lluisfranco.com/2014/04/16/e...network-paths/, mais c'est en VB.NET, et je n'arrive pas à faire la conversion.
Je vous propose tout de même cette solution :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| private static IntPtr GetIconHandleFromFilePath(
string filepath, IconSizeEnum iconsize)
{
var shinfo = new Shell.SHFILEINFO();
const uint SHGFI_SYSICONINDEX = 0x4000;
const int FILE_ATTRIBUTE_NORMAL = 0x80;
const int ILD_TRANSPARENT = 1;
uint flags = SHGFI_SYSICONINDEX;
var retval = SHGetFileInfo(filepath, FILE_ATTRIBUTE_NORMAL,
ref shinfo, Marshal.SizeOf(shinfo), flags);
if (retval == 0) throw (new System.IO.FileNotFoundException());
var iconIndex = shinfo.iIcon;
var iImageListGuid = newGuid("46EB5926-582E-4017-9FDF-E8998DAA0950");
Shell.IImageList iml;
var hres = SHGetImageList((int)iconsize, ref iImageListGuid, out iml);
var hIcon = IntPtr.Zero;
hres = iml.GetIcon(iconIndex, ILD_TRANSPARENT, ref hIcon);
return hIcon;
} |
Merci pour votre aide
Partager