i want to extract icon from exe file.
does anyone know how to do this??
thank you very much
Regards
Estella
i want to extract icon from exe file.
does anyone know how to do this??
thank you very much
Regards
Estella
Quick follow-up and extras to the SHGetFileInfo approach that solved 's question (thanks to for the working sample).
The SHGetFileInfo route is a standard, lightweight way to show an EXE/DLL icon from the system image list; note that SHGetFileInfo sometimes returns a system image-list handle and sometimes an HICON depending on flags, and any HICON returned must be released when no longer needed. SHGetFileInfo also expects COM to be initialized when called from nonstandard threads. (learn.microsoft.com)
Two common alternatives that give more control:
Example (VB6): extract one icon and draw it into a PictureBox (different approach than the SHGetFileInfo/ImageList_Draw code already posted).
' Declarations
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 DrawIcon Lib "user32.dll" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long
Public Sub DrawExeIcon(path As String, index As Long, pic As PictureBox, large As Boolean)
Dim hIcon As Long
If large Then
ExtractIconEx path, index, hIcon, 0&, 1
Else
ExtractIconEx path, index, 0&, hIcon, 1
End If
pic.Cls
Call DrawIcon(pic.hDC, 0, 0, hIcon)
Call DestroyIcon(hIcon)
End Sub Notes and troubleshooting
Key references: SHGetFileInfo, ExtractIconEx, PrivateExtractIcons, DestroyIcon, OleCreatePictureIndirect. (learn.microsoft.com)
Jump to Post— Jx_Man 987Add in your declaration :
Const MAX_PATH As Integer = 260
Jump to Post— Jx_Man 987add this following code in your module :
Public Sub RetrieveIcon(fName As String, DC As PictureBox, icnSize As IconRetrieve) Dim hImgSmall, hImgLarge As Long 'the handle to the system image list DC.Cls Select Case icnSize Case ricnSmall hImgSmall = SHGetFileInfo(fName$, 0&, shinfo, Len(shinfo), BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON) Call …
declared on module...
Private Const SHGFI_DISPLAYNAME = &H200, SHGFI_EXETYPE = &H2000, SHGFI_SYSICONINDEX = &H4000, SHGFI_LARGEICON = &H0, SHGFI_SMALLICON = &H1, SHGFI_SHELLICONSIZE = &H4, SHGFI_TYPENAME = &H400, ILD_TRANSPARENT = &H1, BASIC_SHGFI_FLAGS = SHGFI_TYPENAME Or SHGFI_SHELLICONSIZE Or SHGFI_SYSICONINDEX Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE
Private Type SHFILEINFO
hIcon As Long: iIcon As Long: dwAttributes As Long: szDisplayName As String * MAX_PATH: szTypeName As String * 80
End Type
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbSizeFileInfo As Long, ByVal uFlags As Long) As Long
Private Declare Function ImageList_Draw Lib "Comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hDCDest As Long, ByVal X As Long, ByVal Y As Long, ByVal Flags As Long) As Long
Private shinfo As SHFILEINFO, sshinfo As SHFILEINFO
Public Enum IconRetrieve
ricnLarge = 32
ricnSmall = 16
End Enum Add in your declaration :
Const MAX_PATH As Integer = 260 thanks to completed my declaration.
actually i don't have idea to do this function.
do you know a function to retrieve icon from exe file using my delcaration?
add this following code in your module :
Public Sub RetrieveIcon(fName As String, DC As PictureBox, icnSize As IconRetrieve)
Dim hImgSmall, hImgLarge As Long 'the handle to the system image list
DC.Cls
Select Case icnSize
Case ricnSmall
hImgSmall = SHGetFileInfo(fName$, 0&, shinfo, Len(shinfo), BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)
Call ImageList_Draw(hImgSmall, shinfo.iIcon, DC.hDC, 0, 0, ILD_TRANSPARENT)
Case ricnLarge
hImgLarge& = SHGetFileInfo(fName$, 0&, shinfo, Len(shinfo), BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON)
Call ImageList_Draw(hImgLarge, shinfo.iIcon, DC.hDC, 0, 0, ILD_TRANSPARENT)
End Select
End Sub this function will called like this :
RetrieveIcon lblPath.Caption, PicIcon32, ricnLarge PicIcon32 is picturebox
hope this helps...
yes, got it.
Working like a charm.
RetrieveIcon "C:\Program Files\Winamp\winamp.exe", PicIcon32, ricnLarge Thank you very much
btw if i want to see the small one, i use bellow code :
RetrieveIcon "C:\Program Files\Winamp\winamp.exe", PicIcon32, ricnSmall That right jx??
yes, thats right...
Ok. Thanks again.
you really help me much with great code.
This thread already solved.
you're Welcome...
Happy coding Friend :)
hello every one,
how to extract .exe files using vb 6.0. any one pls help me out
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.