# Function Reference

# _WinAPI_SaveHICONToFile

Saves a specified single or multiple icon (HICON) to the specified icon (.ico) file

#include <WinAPIGdi.au3>
_WinAPI_SaveHICONToFile ( $sFilePath, Const ByRef $vIcon [, $bCompress = 0 [, $iStart = 0 [, $iEnd = -1]]] )

## Parameters

$sFilePath | The name of the .ico file in which to save the icon.
$vIcon | Handle to the icon or array of the icon handles to be save.
$bCompress | [optional] Specifies whether to use PNG compression for the 32 bits-per-pixel icons if its size exceed or equal to 256x256 pixels (262144 bytes), valid values: True - The icon will be saved as a PNG image. False - The icon will be saved directly (Default).
$iStart | [optional] The index of array to start saving at.
$iEnd | [optional] The index of array to stop saving at.

## Return Value

Success: | 1.
Failure: | 0 and sets the @error flag to non-zero.

## Remarks

This function works with 16, 24, and 32 bits-per-pixel icons. Since the icon handles always contains a device-depended
XOR bitmap (DDB), the resulting image that saved in .ico file may differ from the source image.
If the specified icon is a 32 bits-per-pixel icon, and uses the AND bitmask bitmap instead of alpha channel,
it will be converted to an icon with alpha channel (RGB + Alpha).
Note that the icons with PNG compression are supported starting only with Windows Vista. In addition,
not all applications can work with such icons.

## Example

    #include <WinAPIGdi.au3>
    #include <WinAPIIcons.au3>
    #include <WinAPIShellEx.au3>

    Local $aIcon[3] = [48, 32, 16]

    For $i = 0 To UBound($aIcon) - 1
        $aIcon[$i] = _WinAPI_Create32BitHICON(_WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 32, $aIcon[$i], $aIcon[$i]), 1)
    Next
    _WinAPI_SaveHICONToFile(@TempDir & '\MyIcon.ico', $aIcon)
    For $i = 0 To UBound($aIcon) - 1
        _WinAPI_DestroyIcon($aIcon[$i])
    Next

    ShellExecute('mspaint', '"' & @TempDir & '\MyIcon.ico' & '"')