Function Reference


_WinAPI_CreateIconFromResourceEx

Creates an icon or cursor from resource bits describing the icon

#include <WinAPIRes.au3>
_WinAPI_CreateIconFromResourceEx ( $pData, $iSize [, $bIcon = True [, $iXDesiredPixels = 0 [, $iYDesiredPixels = 0 [, $iFlags = 0]]]] )

Parameters

$pData The icon or cursor resource bits. These bits are typically loaded by calls to the _WinAPI_LookupIconIdFromDirectoryEx() and _WinAPI_LoadResource() functions.
$iSize The size, in bytes, of the set of bits pointed to by the $pData parameter.
$bIcon [optional] Specifies whether an icon or a cursor is to be created, valid values:
    True - An icon is to be created (Default).
    False - A cursor is to be created.
$iXDesiredPixels [optional] The desired width, in pixels, of the icon or cursor. If this parameter is zero (Default), the function uses the system metric value to set the width.
$iYDesiredPixels [optional] The desired height, in pixels, of the icon or cursor. If this parameter is zero (Default), the function uses the system metric value to set the height.
$iFlags [optional] This parameter can be one or more of the following values.
    $LR_DEFAULTCOLOR (Default)
    $LR_DEFAULTSIZE
    $LR_MONOCHROME
    $LR_SHARED

Return Value

Success: Handle to the icon or cursor.
Failure: 0, call _WinAPI_GetLastError() to get extended error information.

Remarks

You should call _WinAPI_DestroyIcon() for icons created with _WinAPI_CreateIconFromResourceEx() function.

Related

_WinAPI_DestroyIcon

See Also

Search CreateIconFromResourceEx in MSDN Library.

Example

#include <APIResConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPIRes.au3>

; Load Resources.dll to memory
Local $hInstance = _WinAPI_LoadLibraryEx(@ScriptDir & '\Extras\Resources.dll', $LOAD_LIBRARY_AS_DATAFILE)
If Not $hInstance Then
    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', @ScriptDir & '\Extras\Resources.dll not found.')
    Exit
EndIf

; Load RT_GROUP_ICON resource from Resources.dll library
Local $hResource = _WinAPI_FindResource($hInstance, $RT_GROUP_ICON, 1)
Local $hData = _WinAPI_LoadResource($hInstance, $hResource)
Local $pData = _WinAPI_LockResource($hData)

; Search an integer resource name for the icon that best fits the specified size (48x48)
Local $iIcon = _WinAPI_LookupIconIdFromDirectoryEx($pData, 1, 48, 48)

; Load RT_ICON resource from Resources.dll library
$hResource = _WinAPI_FindResource($hInstance, $RT_ICON, $iIcon)
Local $iSize = _WinAPI_SizeOfResource($hInstance, $hResource)
$hData = _WinAPI_LoadResource($hInstance, $hResource)
$pData = _WinAPI_LockResource($hData)

; Create icon from resource
Local $hIcon = _WinAPI_CreateIconFromResourceEx($pData, $iSize)

; Unload Resources.dll from memory
_WinAPI_FreeLibrary($hInstance)

; Create GUI
GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 128, 128)
GUICtrlCreateIcon('', 0, 40, 40, 48, 48)
GUICtrlSendMsg(-1, $STM_SETIMAGE, 1, $hIcon)
GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE