vb怎样读取一个文件的图标
1个回答
展开全部
'ImageList
Private Const MAX_PATH = 260
Private Const SHGFI_DISPLAYNAME = &H200 ' get display name
Private Const SHGFI_EXETYPE = &H2000 ' return exe type
Private Const SHGFI_LARGEICON = &H0 ' get large icon
Private Const SHGFI_SHELLICONSIZE = &H4 ' get shell size icon
Private Const SHGFI_SMALLICON = &H1 ' get small icon
Private Const SHGFI_SYSICONINDEX = &H4000 ' get system icondex
Private Const SHGFI_TYPENAME = &H400 ' get type name
Private Const ILD_BLEND50 = &H4
Private Const ILD_BLEND25 = &H2
Private Const ILD_TRANSPARENT = &H1
Private Const CLR_NONE = &HFFFFFFFF
Private Const CLR_DEFAULT = &HFF000000
Private Type SHFILEINFO
hIcon As Long ' : icon
iIcon As Long ' : icondex
dwAttributes As Long ' : SFGAO_ flags
szDisplayName As String * MAX_PATH ' : display name (or path)
szTypeName As String * 80 ' : type name
End Type
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
Private Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hdcDst As Long, ByVal x As Long, ByVal y As Long, ByVal fStyle As Long) As Long
Private Declare Function ImageList_DrawEx Lib "comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hdcDst As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal rgbBk As Long, ByVal rgbFg As Long, ByVal fStyle As Long) As Long
Private Sub Form_Load()
Dim hImage As Long, udtFI As SHFILEINFO
'set the graphics mode of form1 to persistent
Me.AutoRedraw = True
'get the handle of the system image list that contains the large icon images
hImage = SHGetFileInfo("c:\thefile.tst", ByVal 0&, udtFI, Len(udtFI), SHGFI_SYSICONINDEX Or SHGFI_LARGEICON)
'draw the icon (normal)
ImageList_Draw hImage, udtFI.iIcon, Me.hDC, 0, 0, ILD_TRANSPARENT
'draw the icon (blended)
ImageList_DrawEx hImage, udtFI.iIcon, Me.hDC, 32, 0, 32, 32, CLR_NONE, CLR_DEFAULT, ILD_BLEND50
End Sub
Private Const MAX_PATH = 260
Private Const SHGFI_DISPLAYNAME = &H200 ' get display name
Private Const SHGFI_EXETYPE = &H2000 ' return exe type
Private Const SHGFI_LARGEICON = &H0 ' get large icon
Private Const SHGFI_SHELLICONSIZE = &H4 ' get shell size icon
Private Const SHGFI_SMALLICON = &H1 ' get small icon
Private Const SHGFI_SYSICONINDEX = &H4000 ' get system icondex
Private Const SHGFI_TYPENAME = &H400 ' get type name
Private Const ILD_BLEND50 = &H4
Private Const ILD_BLEND25 = &H2
Private Const ILD_TRANSPARENT = &H1
Private Const CLR_NONE = &HFFFFFFFF
Private Const CLR_DEFAULT = &HFF000000
Private Type SHFILEINFO
hIcon As Long ' : icon
iIcon As Long ' : icondex
dwAttributes As Long ' : SFGAO_ flags
szDisplayName As String * MAX_PATH ' : display name (or path)
szTypeName As String * 80 ' : type name
End Type
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
Private Declare Function ImageList_Draw Lib "comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hdcDst As Long, ByVal x As Long, ByVal y As Long, ByVal fStyle As Long) As Long
Private Declare Function ImageList_DrawEx Lib "comctl32.dll" (ByVal himl As Long, ByVal i As Long, ByVal hdcDst As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal rgbBk As Long, ByVal rgbFg As Long, ByVal fStyle As Long) As Long
Private Sub Form_Load()
Dim hImage As Long, udtFI As SHFILEINFO
'set the graphics mode of form1 to persistent
Me.AutoRedraw = True
'get the handle of the system image list that contains the large icon images
hImage = SHGetFileInfo("c:\thefile.tst", ByVal 0&, udtFI, Len(udtFI), SHGFI_SYSICONINDEX Or SHGFI_LARGEICON)
'draw the icon (normal)
ImageList_Draw hImage, udtFI.iIcon, Me.hDC, 0, 0, ILD_TRANSPARENT
'draw the icon (blended)
ImageList_DrawEx hImage, udtFI.iIcon, Me.hDC, 32, 0, 32, 32, CLR_NONE, CLR_DEFAULT, ILD_BLEND50
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询