您的位置:首页 > 编程语言 > VB

VB.NET下获取系统图标

2006-04-24 12:45 477 查看
在这里用到一个API函数

Public Declare Function SHGetFileInfo Lib "shell32" ( _
ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef sfi As SHFILEINFO, _
ByVal cbsfi As Integer, _
ByVal uFlags As Integer) As Integer

'获取图标()
Dim ic2 As Icon
Dim HR_Small As Integer
Dim shfi_Small As New SHFILEINFO
HR_Small = SHGetFileInfo(strfile, 0, shfi_Small, Marshal.SizeOf(shfi_Small), SHGFI.SMALLICON Or SHGFI.ICON)

'strfile是要获取图标的文件的路径,可以是文件夹,也可以是文件.

Try
ic2 = Icon.FromHandle(shfi_Small.hIcon)
SmallImage.Images.Add(ic2) '把获得的图片装在ImageList里
Catch ex As Exception
MsgBox(ex.ToString())
End Try

以后显示的时候再来ImageList里来取就是了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: