IImageList::ReplaceIcon method (commoncontrols.h)

Replaces an image with an icon or cursor.

Syntax

HRESULT ReplaceIcon(
  [in]  int   i,
  [in]  HICON hicon,
  [out] int   *pi
);

Parameters

[in] i

Type: int

A value of type int that contains the index of the image to replace. If i is -1, the function adds the image to the end of the list.

[in] hicon

Type: HICON

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

[out] pi

Type: int*

A pointer to an int that will contain the index of the image on return if successful, or -1 otherwise.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

Because the system does not save hicon, you can destroy it after the function returns if the icon or cursor was created by CreateIcon. 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.

To use IImageList::ReplaceIcon, specify Comctl32.dll version 6 in the manifest. For more information on manifests, see Enabling Visual Styles.

Requirements

Requirement Value
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header commoncontrols.h
DLL Comctl32.dll (version 6.0 or later)