Winform中如何获得文件的图标?
如何获得文件的图标,请高手指点下.. --------------------编程问答-------------------- 调用API函数:SHGetFileInfo。 --------------------编程问答-------------------- 能不能给个具体代码示例 --------------------编程问答-------------------- 能不能给个具体代码示例.? --------------------编程问答-------------------- 可以把SHGetFileInfo作为关键字,到网上去搜一下就是了。 --------------------编程问答-------------------- http://support.microsoft.com/kb/319350/zh-cn以上是微软网站上的一个例子。 --------------------编程问答-------------------- Mark下 --------------------编程问答-------------------- --------------------编程问答--------------------
#Region "获取文件图标"
Public Class GetItemBitmap
Private Const SHGFI_ICON As Integer = 256
Private Const SHGFI_SMALLICON As Integer = 1
Private Const SHGFI_LARGEICON As Integer = 0
Private Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As UInteger
<Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=256)> _
Public szDisplayName As String
<Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
<Runtime.InteropServices.DllImport("Shell32.dll")> _
Private Shared Function SHGetFileInfo(ByVal pszPath As String, ByVal dwFileAttributes As UInteger, ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlags As UInteger) As IntPtr
End Function
<System.Runtime.InteropServices.DllImport("user32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto)> _
Private Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
End Function
Public Shared Function GetIcon(ByVal filename As String) As Drawing.Bitmap
Dim iconbitmap As Drawing.Bitmap
Dim shinfo As New SHFILEINFO()
Dim hImgSmall As IntPtr = SHGetFileInfo(filename, 0, shinfo, System.Runtime.InteropServices.Marshal.SizeOf(shinfo), SHGFI_ICON Or SHGFI_SMALLICON)
Dim icon As Drawing.Icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
iconbitmap = icon.ToBitmap()
DestroyIcon(shinfo.hIcon)
Return iconbitmap
End Function
End Class
#End Region
补充:.NET技术 , C#