如何得到Windows各种文件类型默认的图标

 我来答
ae...2@33sn.cc
2017-07-16 · TA获得超过107个赞
知道答主
回答量:226
采纳率:50%
帮助的人:41.8万
展开全部
SHGetFileInfo函数的例子代码:

Option Explicit
Const SHGFI_ICON = &H100
Const SHGFI_DISPLAYNAME = &H200
Const SHGFI_TYPENAME = &H400
Const MAX_PATH = 260
Private Type SHFILEINFO
hIcon As Long ' out: icon
iIcon As Long ' out: icon index
dwAttributes As Long ' out: SFGAO_ flags
szDisplayName As String * MAX_PATH ' out: display name (or path)
szTypeName As String * 80 ' out: type name
End Type
Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
Private Sub Form_Paint()
'KPD-Team 1999
'URL:
'E-Mail: KPDTeam@Allapi.net
Dim FI As SHFILEINFO
'Get file info
SHGetFileInfo "c:\autoexec.bat", 0, FI, Len(FI), SHGFI_DISPLAYNAME Or SHGFI_TYPENAME Or SHGFI_ICON
Me.Cls
Me.Print "Filename: Autoexec.bat"
Me.Print "Typename: " + StripTerminator(FI.szTypeName)
Me.Print "Displayname: " + StripTerminator(FI.szDisplayName)
Me.Print "hIcon: "; FI.hIcon
Me.Print "iIcon: "; FI.iIcon
End Sub
'This fucntion is used to strip al the unnecessary chr$(0)'s
Function StripTerminator(sInput As String) As String
Dim ZeroPos As Integer
'Search the position of the first chr$(0)
ZeroPos = InStr(1, sInput, vbNullChar)
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式