'以下在Form ,一个CommonDialog1 一个Command button 2个PictureBox
Private Sub Command1_Click()
Dim hImgSmall As Long 'the handle to the system image list(Small Icon)
Dim fName As String 'the file name to get icon from
Dim fnFilter As String 'the file name filter
Dim r As Long
Dim hImgLarge As Long 'the handle to the system image list(Large Icon)
Dim Info1 As String, Info2 As String
'get the file from the user fnFilter$ = "All Files (*.*)|*.*|"
fnFilter = fnFilter & "Applications (*.exe)|*.exe|"
fnFilter = fnFilter & "Windows Bitmap (*.bmp)|*.bmp|"
fnFilter = fnFilter & "Icon Files (*.ico)|*.ico"
CommonDialog1.CancelError = True
CommonDialog1.Filter = fnFilter
CommonDialog1.ShowOpen
fName = CommonDialog1.filename
'get the system icon associated with that file
hImgSmall& = SHGetFileInfo(fName$, 0, _
shinfo, Len(shinfo), _
BASIC_SHGFI_FLAGS Or SHGFI_SMALLICON)
hImgLarge& = SHGetFileInfo(fName$, 0&, _
shinfo, Len(shinfo), _
BASIC_SHGFI_FLAGS Or SHGFI_LARGEICON)
'fill in the labels with the image's file data
Info1 = Left$(shinfo.szDisplayName, _
InStr(shinfo.szDisplayName, Chr$(0)) - 1)
Info2 = Left$(shinfo.szTypeName, _
InStr(shinfo.szTypeName, Chr$(0)) - 1)
Debug.Print Info1; Info2
Picture1.Picture = LoadPicture()
Picture1.AutoRedraw = True
Picture2.Picture = LoadPicture()
Picture2.AutoRedraw = True
'draw the associated icons into the pictureboxes
r = ImageList_Draw(hImgSmall&, shinfo.iIcon, Picture1.hDC, 0, 0, ILD_TRANSPARENT)
r = ImageList_Draw(hImgLarge&, shinfo.iIcon, Picture2.hDC, 0, 0, ILD_TRANSPARENT)
'realize the images by assigning its
'image property (where the icon was drawn)
'to the actual picture property
Set Picture1.Picture = Picture1.Image
Set Picture2.Picture = Picture2.Image
End Sub
|