1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
Private Declare Function ShGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal Path As String, ByVal DwAttributes As Integer, ByRef ShInfo As ShFileInfo, ByVal SizeFileInfo As Integer, ByVal Flags As Integer) As IntPtr
Private Const ShGetFileInfo_Icon As Short = &H100S
Private Const ShGetFileInfo_SmallIcon As Short = &H1S
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential, CharSet:=Runtime.InteropServices.CharSet.Ansi)> Public Structure ShFileInfo
Dim HIcon As IntPtr
Dim Icon As Integer
Dim Attributes As Integer
<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=260)> Public DisplayName As String
<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=80)> Public TypeName As String
End Structure
Public Function GetIcon(ByVal FileName As String) As System.Drawing.Icon
Dim ShInfo As New ShFileInfo
Call ShGetFileInfo(FileName, 0, ShInfo, Runtime.InteropServices.Marshal.SizeOf(ShInfo), ShGetFileInfo_Icon Or ShGetFileInfo_SmallIcon)
Return System.Drawing.Icon.FromHandle(ShInfo.HIcon)
End Function |
Partager