VB.NET获取文件默认图标的方法_vb.net教程-查字典教程网
VB.NET获取文件默认图标的方法
VB.NET获取文件默认图标的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:本文实例讲述了VB.NET获取文件默认图标的方法。分享给大家供大家参考。具体如下:该段代码帮助你获取计算机上的任何文件的默认图标,使用She...

本文实例讲述了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程序设计有所帮助。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新vb.net学习
    热门vb.net学习
    编程开发子分类