欢迎来到入门教程网!

vb

当前位置:主页 > 软件编程 > vb >

VB.NET获取文件默认图标的方法

来源:本站原创|时间:2020-01-10|栏目:vb|点击:

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

上一篇:VBA将excel数据表生成JSON文件

栏    目:vb

下一篇:VC中实现文字竖排的简单方法(推荐)

本文标题:VB.NET获取文件默认图标的方法

本文地址:https://www.xiuzhanwang.com/a1/vb/7170.html

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 脚本教程网 版权所有