Added second IExtractIcon.Extract extension to handle getting one icon

pull/180/head
dahall 2020-11-03 09:27:32 -07:00
parent 31e83ac903
commit 79e2b179e1
1 changed files with 46 additions and 0 deletions

View File

@ -175,6 +175,29 @@ namespace Vanara.PInvoke
unsafe HRESULT Extract([MarshalAs(UnmanagedType.LPWStr)] string pszFile, uint nIconIndex, [Optional] HICON* phiconLarge, [Optional] HICON* phiconSmall, uint nIconSize);
}
/// <summary>Extracts an icon image from the specified location.</summary>
/// <param name="exIcon">The <see cref="IExtractIconA"/> instance.</param>
/// <param name="pszFile">A pointer to a null-terminated string that specifies the icon location.</param>
/// <param name="nIconIndex">The index of the icon in the file pointed to by pszFile.</param>
/// <param name="nIconSize">
/// The desired size of the icon, in pixels. The size specified can be the width or height. The width of an icon always equals
/// its height.
/// </param>
/// <param name="phicon">A pointer to an HICON value that receives the handle to the icon. This parameter may be NULL.</param>
/// <returns>Returns S_OK if the function extracted the icon, or S_FALSE if the calling application should extract the icon.</returns>
public static HRESULT Extract(this IExtractIconA exIcon, string pszFile, uint nIconIndex, ushort nIconSize, out SafeHICON phicon)
{
if (exIcon is null) throw new ArgumentNullException(nameof(exIcon));
var sz = nIconSize > 16 ? Macros.MAKELONG(nIconSize, 0) : Macros.MAKELONG(0, nIconSize);
unsafe
{
HICON h1 = default;
var hr = nIconSize > 16 ? exIcon.Extract(pszFile, nIconIndex, &h1, null, sz) : exIcon.Extract(pszFile, nIconIndex, null, &h1, sz);
phicon = h1 == default ? null : new SafeHICON((IntPtr)h1);
return hr;
}
}
/// <summary>Extracts an icon image from the specified location.</summary>
/// <param name="exIcon">The <see cref="IExtractIconA"/> instance.</param>
/// <param name="pszFile">A pointer to a null-terminated string that specifies the icon location.</param>
@ -204,6 +227,29 @@ namespace Vanara.PInvoke
}
}
/// <summary>Extracts an icon image from the specified location.</summary>
/// <param name="exIcon">The <see cref="IExtractIconW"/> instance.</param>
/// <param name="pszFile">A pointer to a null-terminated string that specifies the icon location.</param>
/// <param name="nIconIndex">The index of the icon in the file pointed to by pszFile.</param>
/// <param name="nIconSize">
/// The desired size of the icon, in pixels. The size specified can be the width or height. The width of an icon always equals
/// its height.
/// </param>
/// <param name="phicon">A pointer to an HICON value that receives the handle to the icon. This parameter may be NULL.</param>
/// <returns>Returns S_OK if the function extracted the icon, or S_FALSE if the calling application should extract the icon.</returns>
public static HRESULT Extract(this IExtractIconW exIcon, string pszFile, uint nIconIndex, ushort nIconSize, out SafeHICON phicon)
{
if (exIcon is null) throw new ArgumentNullException(nameof(exIcon));
var sz = nIconSize > 16 ? Macros.MAKELONG(nIconSize, 0) : Macros.MAKELONG(0, nIconSize);
unsafe
{
HICON h1 = default;
var hr = nIconSize > 16 ? exIcon.Extract(pszFile, nIconIndex, &h1, null, sz) : exIcon.Extract(pszFile, nIconIndex, null, &h1, sz);
phicon = h1 == default ? null : new SafeHICON((IntPtr)h1);
return hr;
}
}
/// <summary>Extracts an icon image from the specified location.</summary>
/// <param name="exIcon">The <see cref="IExtractIconW"/> instance.</param>
/// <param name="pszFile">A pointer to a null-terminated string that specifies the icon location.</param>