首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

用listview实现模拟资源管理器,如何样实现文件图标和系统的文件关联同步

2012-03-12 
用listview实现模拟资源管理器,怎么样实现文件图标和系统的文件关联同步用listview实现模拟资源管理器,怎

用listview实现模拟资源管理器,怎么样实现文件图标和系统的文件关联同步
用listview实现模拟资源管理器,怎么样实现文件图标和系统的文件关联同步

[解决办法]
Imports System
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.IO

Public Class IconExtractor

Private Const SHGFI_SMALLICON = &H1
Private Const SHGFI_LARGEICON = &H0
Private Const SHGFI_ICON = &H100
Private Const SHGFI_USEFILEATTRIBUTES = &H10

Public Enum IconSize
SmallIcon = SHGFI_SMALLICON
LargeIcon = SHGFI_LARGEICON
End Enum

<StructLayout(LayoutKind.Sequential)> _
Private Structure SHFILEINFO
' pointer to icon handle
Public hIcon As IntPtr
' icon index
Public iIcon As Integer
' not used in this example
Public dwAttributes As Integer
' file pathname--marshal this as
' an unmanaged LPSTR of MAX_SIZE
<MarshalAs(UnmanagedType.LPStr, SizeConst:=260)> _
Public szDisplayName As String
' file type--marshal as unmanaged
' LPSTR of 80 chars
<MarshalAs(UnmanagedType.LPStr, SizeConst:=80)> _
Public szTypeName As String
End Structure

Private Declare Auto Function SHGetFileInfo _
Lib "shell32 " (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer

Public Shared Function GetSmallIcon(ByVal fn As String) As Icon
Return IconExtractor.GetIcon(fn, SHGFI_SMALLICON)
End Function

Public Shared Function GetLargeIcon(ByVal fn As String) As Icon
Return IconExtractor.GetIcon(fn, SHGFI_LARGEICON)
End Function

Private Shared Function GetIcon(ByVal fn As String, ByVal anIconSize As Integer) As Icon

Dim aSHFileInfo As New SHFILEINFO()
Dim cbFileInfo As Integer = Marshal.SizeOf(aSHFileInfo)
Dim uflags As Integer = SHGFI_ICON Or SHGFI_USEFILEATTRIBUTES Or anIconSize
Try
SHGetFileInfo(fn, 0, aSHFileInfo, cbFileInfo, uflags)
Return Icon.FromHandle(aSHFileInfo.hIcon)
Catch ex As Exception
Return Nothing
End Try



End Function




End Class

热点排行