从文件中解出图标 作者:Ray 邮箱:rgss@inreach.com   从任一文件中解出图标。  This code extracts the icon from any file and saves it into a image list to be used in listviews, treeviews, and the like. It will extract the windows icon for any file, doesn't have to be a dll, ico or exe. Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As Any, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long Public Declare Function OleCreatePictureIndirect _ Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, _ ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long Public Type PicBmp   Size As Long   tType As Long   hBmp As Long   hPal As Long   Reserved As Long End Type Public Type GUID   Data1 As Long   Data2 As Integer   Data3 As Integer   Data4(7) As Byte End Type Public Type SHFILEINFO  hicon As Long  iIcon As Long  dwAttributes As Long  szDisplayName As String * 260  szTypeName As String * 80 End Type ' ***************** PUT THIS IN YOUR FORM CODE ************************* ' YOU MUST Make a Reference To Standard OLE Types ' Put a command button, listview, and imagelist on your form ' and set the imagelist properties of the listview to imagelist1 ' and set the View property of the listview to lvwList Public Function GetIconFromFile(FileName As String, IconIndex As Long, UseLargeIcon As Boolean) As Picture Dim b As SHFILEINFO Dim retval As Long retval = SHGetFileInfo(FileName, 0, b, Len(b), &H100) 'IPicture requires a reference to "Standard OLE Types." Dim pic As PicBmp Dim IPic As IPicture Dim IID_IDispatch As GUID With IID_IDispatch .Data1 = &H20400 .Data4(0) = &HC0 .Data4(7) = &H46 End With With pic .Size = Len(b) .tType = vbPicTypeIcon .hBmp = b.hicon 'Handle to bitmap. End With 'Create Picture object. Call OleCreatePictureIndirect(pic, IID_IDispatch, 1, IPic) 'Return the new Picture object. Set GetIconFromFile = IPic End Function Private Sub Command1_Click() Dim i As Integer Dim itm As ListItem ImageList1.ListImages.Add , , GetIconFromFile("c:\anyValidFileorFolder", 0, True) ListView1.Icons = ImageList1   For i = 1 To ImageList1.ListImages.Count   Set itm = ListView1.ListItems.Add(, , , , ImageList1.ListImages.Item(i).Index)   Next i ' Questions? Comments? Email to rgss@inreach.com End Sub