VB.NET獲取文件默許圖標的辦法。本站提示廣大學習愛好者:(VB.NET獲取文件默許圖標的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是VB.NET獲取文件默許圖標的辦法正文
本文實例講述了VB.NET獲取文件默許圖標的辦法。分享給大家供大家參考。詳細如下:
該段代碼協助你獲取計算機上的任何文件的默許圖標,運用Shell32.dll。
Private Structure SHFILEINFO Public hIcon As IntPtr Public iIcon As Integer Public dwAttributes As Integer <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _ Public szDisplayName As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _ Public szTypeName As String End Structure Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _ (ByVal pszPath As String, _ ByVal dwFileAttributes As Integer, _ ByRef psfi As SHFILEINFO, _ ByVal cbFileInfo As Integer, _ ByVal uFlags As Integer) As IntPtr Private Const SHGFI_ICON = &H100 Private Const SHGFI_SMALLICON = &H1 Private Const SHGFI_LARGEICON = &H0 Private nIndex = 0 Private hImgLarge As IntPtr 'The handle to the system image list. Private Function GetLargeIcon(ByVal FilePath As String) As System.Drawing.Icon Dim fName As String Dim shinfo As SHFILEINFO shinfo = New SHFILEINFO() shinfo.szDisplayName = New String(Chr(0), 260) shinfo.szTypeName = New String(Chr(0), 80) fName = FilePath hImgLarge = SHGetFileInfo(fName, 0, shinfo, Marshal.SizeOf(shinfo), SHGFI_ICON Or SHGFI_LARGEICON) Dim myIcon As System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon) Return myIcon End Function Private Function GetSmallIcon(ByVal FilePath As String) As System.Drawing.Icon Dim fName As String Dim shinfo As SHFILEINFO shinfo = New SHFILEINFO() shinfo.szDisplayName = New String(Chr(0), 260) shinfo.szTypeName = New String(Chr(0), 80) fName = FilePath hImgLarge = SHGetFileInfo(fName, 0, shinfo, Marshal.SizeOf(shinfo), SHGFI_ICON Or SHGFI_SMALLICON) Dim myIcon As System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon) Return myIcon End Function
希望本文所述對大家的VB.NET順序設計有所協助。