private Icon getIcon(bool large) { int iconIndex; var iconPath = new StringBuilder(260, 260); if (_linkA == null) { _linkW.GetIconLocation(iconPath, iconPath.Capacity, out iconIndex); } else { _linkA.GetIconLocation(iconPath, iconPath.Capacity, out iconIndex); } var iconFile = iconPath.ToString(); if (iconFile.Length == 0) { var flags = FileIcon.ShGetFileInfoConstants.SHGFI_ICON | FileIcon.ShGetFileInfoConstants.SHGFI_ATTRIBUTES; if (large) { flags = flags | FileIcon.ShGetFileInfoConstants.SHGFI_LARGEICON; } else { flags = flags | FileIcon.ShGetFileInfoConstants.SHGFI_SMALLICON; } var fileIcon = new FileIcon(Target, flags); return(fileIcon.ShellIcon); } var hIconEx = new[] { IntPtr.Zero }; if (large) { NativeMethods.ExtractIconEx( iconFile, iconIndex, hIconEx, null, 1); } else { NativeMethods.ExtractIconEx( iconFile, iconIndex, null, hIconEx, 1); } Icon icon = null; if (hIconEx[0] != IntPtr.Zero) { icon = Icon.FromHandle(hIconEx[0]); //UnManagedMethods.DestroyIcon(hIconEx[0]); } return(icon); }
private Icon getIcon(bool large) { int iconIndex; var iconPath = new StringBuilder(260, 260); if (_linkA == null) { _linkW.GetIconLocation(iconPath, iconPath.Capacity, out iconIndex); } else { _linkA.GetIconLocation(iconPath, iconPath.Capacity, out iconIndex); } var iconFile = iconPath.ToString(); if (iconFile.Length == 0) { var flags = FileIcon.ShGetFileInfoConstants.SHGFI_ICON | FileIcon.ShGetFileInfoConstants.SHGFI_ATTRIBUTES; if (large) { flags = flags | FileIcon.ShGetFileInfoConstants.SHGFI_LARGEICON; } else { flags = flags | FileIcon.ShGetFileInfoConstants.SHGFI_SMALLICON; } var fileIcon = new FileIcon(Target, flags); return fileIcon.ShellIcon; } var hIconEx = new[] {IntPtr.Zero}; if (large) { NativeMethods.ExtractIconEx( iconFile, iconIndex, hIconEx, null, 1); } else { NativeMethods.ExtractIconEx( iconFile, iconIndex, null, hIconEx, 1); } Icon icon = null; if (hIconEx[0] != IntPtr.Zero) { icon = Icon.FromHandle(hIconEx[0]); //UnManagedMethods.DestroyIcon(hIconEx[0]); } return icon; }