CreateIconFromResourceEx function

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

Syntax


HICON WINAPI CreateIconFromResourceEx(
  _In_  PBYTE pbIconBits,
  _In_  DWORD cbIconBits,
  _In_  BOOL fIcon,
  _In_  DWORD dwVersion,
  _In_  int cxDesired,
  _In_  int cyDesired,
  _In_  UINT uFlags
);

Parameters

pbIconBits [in]

Type: PBYTE

The icon or cursor resource bits. These bits are typically loaded by calls to the LookupIconIdFromDirectoryEx and LoadResource functions.

cbIconBits [in]

Type: DWORD

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

fIcon [in]

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.

dwVersion [in]

Type: DWORD

The version number of the icon or cursor format for the resource bits pointed to by the pbIconBits 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.

cxDesired [in]

Type: int

The desired width, in pixels, of the icon or cursor. If this parameter is zero, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width.

cyDesired [in]

Type: int

The desired height, in pixels, of the icon or cursor. If this parameter is zero, the function uses the SM_CYICON or SM_CYCURSOR system metric value to set the height.

uFlags [in]

Type: UINT

A combination of the following values.

ValueMeaning
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. If the resource contains multiple images, the function uses the size of the first image.

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.

When loading a system icon or cursor, you must use LR_SHARED or the function will fail to load the resource.

 

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 created with CreateIconFromResourceEx.

Examples

For an example, see Sharing Icon Resources.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
CreateIconFromResource
CreateIconIndirect
DestroyIcon
GetIconInfo
LoadResource
LookupIconIdFromDirectoryEx
Conceptual
Icons
Other Resources
BITMAPINFOHEADER

 

 

Community Additions

ADD
Show:
© 2014 Microsoft