其实在上面那个模块中还可以使用API:
Public Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
那样会简单些!
Private Const MAX_PATH = 260
Private Const SHGFI_ICON = &H100
Private Const SHGFI_SYSICONINDEX = &H4000 ' get system icon index
Private Const SHGFI_LARGEICON = &H0 ' get large icon
Private Const SHGFI_SMALLICON = &H1 ' get small icon
Private Const ILD_TRANSPARENT = &H1 ' 透明
Private Type SHFILEINFO
hIcon As Long ' out: icon
iIcon As Long ' out: icon index
dwAttributes As Long ' out: SFGAO_ flags
szDisplayName As String * MAX_PATH ' out: display name (or path)
szTypeName As String * 80 ' out: type name
End Type
Global lIcon&
Global sSourcePgm$
Global sDestFile$
Public Declare Function ExtractIconAPI Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Public Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl&, ByVal i&, ByVal hDCDest&, ByVal x&, ByVal y&, ByVal flags&) As Long
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
'
Public Function GetIcon(ByVal sPath$, oPictureBox As PictureBox) As Long
Dim xPixels&, yPixels&
xPixels = Screen.TwipsPerPixelX
yPixels = Screen.TwipsPerPixelY
Dim himl&, rtn&
Dim shinfo As SHFILEINFO
Dim picLeft As Long
Dim picTop As Long
himl = SHGetFileInfo(sPath, 0&, shinfo, Len(shinfo), SHGFI_SYSICONINDEX Or SHGFI_LARGEICON)