Function Reference


_WinAPI_LookupIconIdFromDirectoryEx

Searches through icon or cursor data for the icon or cursor that best fits the current display device

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

Parameters

$pData The icon or cursor directory data. Because this function does not validate the resource data,
it causes a general protection (GP) fault or returns an undefined value if presbits is not pointing to validresource data.
$bIcon [optional] Specifies whether an icon or a cursor is sought, valid values:
    True - The function is searching for an icon (Default).
    False - The function is searching for a cursor.
$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.
$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.
$iFlags [optional] This parameter can be one or more of the following values.
    $LR_DEFAULTCOLOR (Default)
    $LR_MONOCHROME

Return Value

Success: An integer resource identifier for the icon or cursor that best fits the current display device.
Failure: 0, call _WinAPI_GetLastError() to get extended error information.

Remarks

The icon directory is loaded from a resource file with resource type $RT_GROUP_ICON (or $RT_GROUP_CURSOR),
and an integer resource name for the specific icon to be loaded.
_WinAPI_LookupIconIdFromDirectoryEx() returns an integer identifier that is the resource name of the icon that best fits the current display device.

See Also

Search LookupIconIdFromDirectoryEx in MSDN Library.

Example

#include <APIResConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPIIcons.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