/// <summary> /// Gets the index of the icon that best fits the current display device. /// </summary> /// <param name="desiredSize">Specifies the desired size of the icon.</param> /// <param name="isMonochrome">Specifies whether to get the monochrome icon or the colored one.</param> /// <returns>The icon index.</returns> public int GetBestFitIconIndex(Size desiredSize, bool isMonochrome) { int iconIndex = 0; LookupIconIdFromDirectoryExFlags flags = LookupIconIdFromDirectoryExFlags.LR_DEFAULTCOLOR; if (isMonochrome) { flags = LookupIconIdFromDirectoryExFlags.LR_MONOCHROME; } IntPtr resBits = Marshal.AllocHGlobal(this.ResourceRawData.Length); Marshal.Copy(this.ResourceRawData, 0, resBits, this.ResourceRawData.Length); try { iconIndex = DllImports.LookupIconIdFromDirectoryEx(resBits, true, desiredSize.Width, desiredSize.Height, flags); } finally { Marshal.FreeHGlobal(resBits); } return(iconIndex); }
public static extern unsafe int LookupIconIdFromDirectoryEx( byte *presbits, [MarshalAs(UnmanagedType.Bool)] bool fIcon, int cxDesired, int cyDesired, LookupIconIdFromDirectoryExFlags Flags);
public static extern int LookupIconIdFromDirectoryEx(IntPtr presbits, bool fIcon, int cxDesired, int cyDesired, LookupIconIdFromDirectoryExFlags Flags);
public static extern unsafe int LookupIconIdFromDirectoryEx( byte* presbits, [MarshalAs(UnmanagedType.Bool)] bool fIcon, int cxDesired, int cyDesired, LookupIconIdFromDirectoryExFlags Flags);