View Full Version : Giúp mình về VB.Net hiện thị icon thư mục?
toiditimtoi992
15-01-2011, 12:59
mình đang tìm hiểu về VB.Net , vấn đề bây giờ là mình đang muốn dùng lệnh để lấy icon của một thư mục hay một file nào đó trong ổ đĩa, sau đó hiện thị nó trong một pictureBox.
Bạn nào có thể chỉ cho mình chút nhé, các bạn code luôn thfi càng tốt,mình cảm ơn nhiều
Đây có phải cái bạn cần?:
Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, ByVal uFlagsn As SHGFI) As Integer
<StructLayout(LayoutKind.Sequential)> _
Private Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
<MarshalAs(UnmanagedType.LPStr, SizeConst:=260)> Public szDisplayName As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=80)> Public szTypeName As String
Public Sub New(ByVal B As Boolean)
hIcon = IntPtr.Zero
iIcon = 0
dwAttributes = 0
szDisplayName = vbNullString
szTypeName = vbNullString
End Sub
End Structure
Public Function GetDefaultIcon(ByVal Path As String, Optional ByVal IconSize As enIconSize = enIconSize.SmallIcon, Optional ByVal SaveIconPath As String = "") As Icon
Dim info As New SHFILEINFO(True)
Dim cbSizeInfo As Integer = Marshal.SizeOf(info)
Dim flags As SHGFI = SHGFI.Icon Or SHGFI.UseFileAttributes
Try
flags = flags + IconSize
SHGetFileInfo(Path, 256, info, cbSizeInfo, flags)
GetDefaultIcon = Icon.FromHandle(info.hIcon)
If SaveIconPath <> "" Then
Dim FileStream As New IO.FileStream(SaveIconPath, IO.FileMode.Create)
GetDefaultIcon.Save(FileStream)
FileStream.Close()
End If
Catch ex As Exception
ErrorMessage("Fehler in GetDefaultIcon()! " + ex.Message)
Return Nothing
End Try
end function
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.