UDF > WinAPIEx > ShellEx >


_WinAPI_ShellExtractAssociatedIcon

Obtient le handle de l'icône associée à un fichier spécifié

#include <WinAPIShellEx.au3>
_WinAPI_ShellExtractAssociatedIcon ( $sFilePath [, $bSmall = False] )

Paramètres

$sFilePath Le chemin complet et le nom du fichier qui contient l'icône, ou son extension, comme ".txt ".
$bSmall [optionnel] Spécifie s'il faut extraire une petite icône, les valeurs possibles sont:
    True - Extrait une petite icône.
    False - Extrait une grande icône (par défaut).

Valeur de retour

Succès: Retourne le handle de l'icône.
Échec: Retourne 0 et définit @error <> 0.

Remarque

Lorsque vous avez fini d'utiliser l'icône, détruisez-là en utilisant la fonction _WinAPI_DestroyIcon().

En relation

_WinAPI_DestroyIcon

Exemple

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPIIcons.au3>
#include <WinAPIShellEx.au3>
#include <WindowsConstants.au3>

Local $hIcon, $sKey, $iCount = 1, $bFirst = False
Local $tSHFILEINFO = DllStructCreate($tagSHFILEINFO)
Local $aExt[101] = [0]

RegRead('HKCR\.x', '')

$sKey = RegEnumKey('HKCR', $iCount)

While @error <> 0 And Not $bFirst
    If StringLeft($sKey, 1) = '.' Then
        RegRead('HKCR\' & $sKey, '')
        If Abs(@error) <> 1 Then
            $aExt[0] += 1
            If $aExt[0] > UBound($aExt) - 1 Then
                ReDim $aExt[UBound($aExt) + 100]
            EndIf
            $aExt[$aExt[0]] = $sKey
        EndIf
        $bFirst = True
    EndIf
    $iCount += 1
    $sKey = RegEnumKey('HKCR', $iCount)    
WEnd

Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 280, 391)

Local $idListview = GUICtrlCreateListView('', 10, 10, 260, 344, BitOR($LVS_DEFAULT, $LVS_NOCOLUMNHEADER), $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_INFOTIP))
_GUICtrlListView_InsertColumn($idListview, 0, '', 238)
Local $hImageList = _GUIImageList_Create(16, 16, 5, 1)
_GUICtrlListView_SetImageList($idListview, $hImageList, 1)
Local $idButton = GUICtrlCreateButton('OK', 105, 361, 70, 23)

For $i = 1 To $aExt[0]
    $hIcon = _WinAPI_ShellExtractAssociatedIcon($aExt[$i], 1)
    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
    _GUICtrlListView_AddItem($idListview, $aExt[$i], $i - 1)
    _WinAPI_DestroyIcon($hIcon)
Next

GUISetState(@SW_SHOW)

Local $iMsg
Do
    $iMsg = GUIGetMsg()
Until $iMsg = $GUI_EVENT_CLOSE Or $iMsg = $idButton