CreateIcon function (winuser.h)
Creates an icon that has the specified size, colors, and bit patterns.
To create a colored icon at run time you can use the CreateIconIndirect function, which creates a icon based on the content of an ICONINFO structure.
Syntax
HICON CreateIcon(
[in, optional] HINSTANCE hInstance,
[in] int nWidth,
[in] int nHeight,
[in] BYTE cPlanes,
[in] BYTE cBitsPixel,
[in] const BYTE *lpbANDbits,
[in] const BYTE *lpbXORbits
);
Parameters
[in, optional] hInstance
Type: HINSTANCE
A handle to the instance of the module creating the icon.
[in] nWidth
Type: int
The width, in pixels, of the icon. See remarks.
[in] nHeight
Type: int
The height, in pixels, of the icon. See remarks.
[in] cPlanes
Type: BYTE
The number of planes in the XOR bitmask of the icon. See remarks.
[in] cBitsPixel
Type: BYTE
The number of bits-per-pixel in the XOR bitmask of the icon.
[in] lpbANDbits
Type: const BYTE*
An array of bytes that contains the bit values for the AND bitmask of the icon. This bitmask describes a monochrome bitmap. See remarks.
[in] lpbXORbits
Type: const BYTE*
An array of bytes that contains the bit values for the XOR bitmask of the icon. This bitmask describes a monochrome or color bitmap. See remarks.
Return value
Type: HICON
If the function succeeds, the return value is a handle to an icon.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Remarks
To determine the nominal size of the icon, use the GetSystemMetrics function, specifying the SM_CXICON or SM_CYICON value. Also, you can use the DPI-aware version of this API, see (GetSystemMetricsForDpi)(/windows/win32/api/winuser/nf-winuser-getsystemmetricsfordpi). For more information see Icon Sizes and High DPI Desktop Application Development on Windows.
For more information about lpbANDbits and lpbXORbits parameters see description of lpBits parameter of CreateBitmap function.
In case of monochrome icon CreateIcon applies the following truth table to the AND and XOR bitmasks:
AND bitmask | XOR bitmask | Display |
---|---|---|
0 | 0 | Black |
0 | 1 | White |
1 | 0 | Screen |
1 | 1 | Reverse screen |
When you are finished using the icon, destroy it using the DestroyIcon function.
Examples
For an example, see Creating an Icon.
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 |