CreateIconFromResourceEx function (winuser.h)

Creates an icon or cursor from resource bits describing the icon.

Syntax

HICON CreateIconFromResourceEx(
  [in] PBYTE presbits,
  [in] DWORD dwResSize,
  [in] BOOL  fIcon,
  [in] DWORD dwVer,
  [in] int   cxDesired,
  [in] int   cyDesired,
  [in] UINT  Flags
);

Parameters

[in] presbits

Type: PBYTE

The DWORD-aligned buffer pointer containing the icon (RT_ICON) or cursor (RT_CURSOR) resource bits. These bits are typically loaded by calls to the LookupIconIdFromDirectoryEx and LoadResource functions.

See Cursor and Icon Resources for more info on icon and cursor resource format.

[in] dwResSize

Type: DWORD

The size, in bytes, of the set of bits pointed to by the pbIconBits parameter.

[in] fIcon

Type: BOOL

Indicates whether an icon or a cursor is to be created. If this parameter is TRUE, an icon is to be created. If it is FALSE, a cursor is to be created.

The LOCALHEADER structure defines cursor hotspot and is the first data read from the cursor resource bits.

[in] dwVer

Type: DWORD

The version number of the icon or cursor format for the resource bits pointed to by the presbits parameter. The value must be greater than or equal to 0x00020000 and less than or equal to 0x00030000. This parameter is generally set to 0x00030000.

[in] cxDesired

Type: int

The width, in pixels, of the icon or cursor. If this parameter is zero and the Flags parameter is LR_DEFAULTSIZE, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource width.

[in] cyDesired

Type: int

The height, in pixels, of the icon or cursor. If this parameter is zero and the Flags parameter is LR_DEFAULTSIZE, the function uses the SM_CYICON or SM_CYCURSOR system metric value to set the height. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource height.

[in] Flags

Type: UINT

A combination of the following values.

Value Meaning
LR_DEFAULTCOLOR
0x00000000
Uses the default color format.
LR_DEFAULTSIZE
0x00000040
Uses the width or height specified by the system metric values for cursors or icons, if the cxDesired or cyDesired values are set to zero. If this flag is not specified and cxDesired and cyDesired are set to zero, the function uses the actual resource size.
LR_MONOCHROME
0x00000001
Creates a monochrome icon or cursor.
LR_SHARED
0x00008000
Shares the icon or cursor handle if the icon or cursor is created multiple times. If LR_SHARED is not set, a second call to CreateIconFromResourceEx for the same resource will create the icon or cursor again and return a different handle.

When you use this flag, the system will destroy the resource when it is no longer needed.

Do not use LR_SHARED for icons or cursors that have non-standard sizes, that may change after loading, or that are loaded from a file.

Return value

Type: HICON

If the function succeeds, the return value is a handle to the icon or cursor.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The CreateIconFromResource, CreateIconFromResourceEx, CreateIconIndirect, GetIconInfo, and LookupIconIdFromDirectoryEx functions allow shell applications and icon browsers to examine and use resources throughout the system.

You should call DestroyIcon for icons or DestroyCursor for cursors created with CreateIconFromResourceEx.

Examples

For an example, see Sharing Icon Resources.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll

See also

BITMAPINFOHEADER

Conceptual

CreateIconFromResource

CreateIconIndirect

DestroyIcon

GetIconInfo

Icons

LoadResource

LookupIconIdFromDirectoryEx

Other Resources

Reference