Les Snippets

Connexion

Extraire et Afficher une Icone d'un fichier dll, exe

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 01/04/2006 00:55:44 et initié par Gobillot [Liste]
Date de mise à jour : 09/04/2006 14:19:15
Vue : 13765
Catégorie(s) : Graphique
Langages dispo pour ce code :
- VB6
- Delphi 5



Langage : VB6
Date ajout : 01/04/2006
Posté par Gobillot [Liste]
Const MAX_PATH = 260
 Const DI_MASK = &H1
 Const DI_IMAGE = &H2
 Const DI_NORMAL = &H3
 Const DI_COMPAT = &H4
 Const DI_DEFAULTSIZE = &H8
 
 
 Private Declare Function SHChangeIconDialog Lib "shell32" Alias "#62" (ByVal owner As Long, ByVal pszFileName As String, pdwBufferSize As Long, pdwIndex As Long) As Boolean
 Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long
 Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
 Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
 
 
 Private Sub ExtractIcone(Lechemin As String)
    Dim sFileName  As String
    Dim sUnicode   As String
    Dim nIconIdx   As Long
    Dim hSmallIcon As Long
    Dim hLargeIcon As Long
    Dim Pos        As Long
    
    sFileName = Lechemin & String$(MAX_PATH - Len(sFileName), 0)
    
    sUnicode = StrConv(sFileName, vbUnicode)
   
    If SHChangeIconDialog(Me.hWnd, sUnicode, 0, nIconIdx) Then
    
       sFileName = StrConv(sUnicode, vbFromUnicode)
       Pos = InStr(sFileName, vbNullChar)
       If Pos Then sFileName = Left$(sFileName, Pos - 1)
    
       If ExtractIconEx(sFileName, nIconIdx, hLargeIcon, hSmallIcon, 1) > 0 Then
          DrawIconEx Me.hdc, 0, 8, hSmallIcon, 0, 0, 0, 0, DI_NORMAL
          DrawIconEx Me.hdc, 32, 8, hLargeIcon, 0, 0, 0, 0, DI_NORMAL
          DestroyIcon hSmallIcon
          DestroyIcon hLargeIcon
          End If
       End If
 
 End Sub
 
 
 Rem utilisation
    ExtractIcone ("shell32.dll")
 
 
 
Langage : Delphi 5
Date ajout : 12/08/2006
Posté par cirec [Liste]

// à déclarer dans la partie Interface
Function PickIconDlgW(OwnerWnd: HWND; lpstrFile: PWideChar; var nMaxFile: LongInt; var lpdwIconIndex: LongInt): LongBool; stdcall; external
'SHELL32.DLL' index 62; 


Implementation
Uses ShellApi;  // pour  ExtractIconExW
 

// Utilisation :
Procedure TfrmMain.btn_ChangeIconeClick(Sender: TObject);
Var
  FileName :  array[0..MAX_PATH - 1] of WideChar;
  Size, Index: LongInt;
  hLargeIcon, hSmallIcon : HIcon;
Begin
  Size := MAX_PATH;
  StringToWideChar('%SystemRoot%\system32\Shell32.dll', FileName, MAX_PATH);
  // ouvre le Dialogue Changer d'Icône
  If PickIconDlgW(Self.Handle, FileName, Size, Index) Then
    If (Index <> -1) Then
    If ExtractIconExW( FileName, Index, hLargeIcon, hSmallIcon, 1) > 0 Then
    Begin
      // on change l'icône de la fiche principale
      Icon.Handle := hSmallIcon;
      // et on dessine le LargeIcone sur la fiche
      DrawIcon(Canvas.Handle, 10, 10, hLargeIcon);
      // Et on libère la mémoire
      DestroyIcon(hLargeIcon);
      DestroyIcon(hSmallIcon);
    End;
End;



Snippets en rapport avec : Image, Icone, Extraire, Ico, Dll



Codes sources en rapport avec : Image, Icone, Extraire, Ico, Dll

{Visual Basic, VB6, VB.NET, VB 2005} EXTRACTION DES ICONES D'UN FICHIER .EXE
La code utilise l'api windows pour extraire les icones d'une executable (metadata). On doit ajout...

{C / C++ / C++.NET} QUICKSEE 1.0
un Clone Acdsee (version 2) en c++ trouver sur le web lit les image format BMP; DIB; EMF; ...

{C / C++ / C++.NET} DLL POUR OUVRIR DES IMAGES AU FORMAT JPG, BMP VOIRE GIF...
Cette DLL est inspirée de la source de vecchio56: http://www.cppfrance.com/codes/IMAGES-JPG-GIF-SAN...

{Visual Basic, VB6, VB.NET, VB 2005} OBTENEZ L'ICÔNE D'UN FICHIER GRÂCE À SON EXTENSION.
Petite "class" avec une propriété et une méthode. Utilisation très Simple, Le tout avec un exemple e...

{JAVA / J2EE} JFIFEXTRACT
Cette appli en ligne de commande permet d'extraire les images jpeg (format JFIF) de différents types...

{Visual Basic, VB6, VB.NET, VB 2005} EXTRACTION DES ICÔNES DES MENU D'OFFICE
Chose demander plusieurs fois sur le forum. J'ai donc décider de faire un petit code simple qui per...

{Delphi} CHARGER DES IMAGES A PARTIR D'UNE DLL
Charger des images a partir d'une DLL...

{Delphi} TRANSPARENCE DANS LA FORM (TROUS)
Voici une source permetant de voir comment faire un trou dans une form et (sur la form2) la transpar...

{C# / C#.NET} OBTENIR L'ICÔNE D'UN FICHIER
Comment obtenir l'icône d'un fichier...

{JAVA / J2EE} TÉLÉCHARGEMENT D'IMAGES (POCHETTES CD, DVD, LIVRES...) SUR INTERNET
Petite fonction permettant de télécharger des images de cds, bd, livres, dvd, films, affiches par r...