考试首页 | 考试用书 | 培训课程 | 模拟考场 | 考试论坛  
  当前位置:编程开发 > DotNET > VB.Net > 文章内容
  

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

 [ 2017年7月26日 ] 【

本文实例讲述了VB.NET获取文件默认图标的方法。分享给大家供大家参考。具体如下:

该段代码帮助你获取计算机上的任何文件的默认图标,使用Shell32.dll。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Private Structure SHFILEINFO
  Public hIcon As IntPtr
  Public iIcon As Integer
  Public dwAttributes As Integer
   _
  Public szDisplayName As String
   _
  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程序设计有所帮助。

本文纠错】【告诉好友】【打印此文】【返回顶部
将考试网添加到收藏夹 | 每次上网自动访问考试网 | 复制本页地址,传给QQ/MSN上的好友 | 申请链接 | 意见留言 TOP
关于本站  网站声明  广告服务  联系方式  站内导航  考试论坛
Copyright © 2007-2013 中华考试网(Examw.com) All Rights Reserved