ImageList_ReplaceIcon function (commctrl.h)

Replaces an image with an icon or cursor.


int ImageList_ReplaceIcon(
  [in] HIMAGELIST himl,
  [in] int        i,
  [in] HICON      hicon


[in] himl


A handle to the image list.

[in] i

Type: int

The index of the image to replace. If i is -1, the function appends the image to the end of the list.

[in] hicon


The handle to the icon or cursor that contains the bitmap and mask for the new image.

Return value

Type: int

Returns the index of the image if successful, or -1 otherwise.


Because the system does not save hicon, you can destroy it after the function returns if the icon or cursor was created by the CreateIcon function. You do not need to destroy hicon if it was loaded by the LoadIcon function; the system automatically frees an icon resource when it is no longer needed.


Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header commctrl.h
Library Comctl32.lib
DLL Comctl32.dll
API set ext-ms-win-shell-comctl32-init-l1-1-1 (introduced in Windows 10, version 10.0.14393)