VB问题?这个是什么控件(有图)

2024-11-17 00:34:17
推荐回答(4个)
回答1:

Public Type TypeIcon
cbSize As Long
picType As PictureTypeConstants
hIcon As Long
End Type

Public Type CLSID
id(16) As Byte
End Type

Public Const MAX_PATH = 260

Public Type SHFILEINFO
hIcon As Long '图标句柄
iIcon As Long '图标索引号
dwAttributes As Long '文件属性值
szDisplayName As String * MAX_PATH '文件的显示名
szTypeName As String * 80 '文件的类型名
End Type

Public Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" (pDicDesc As TypeIcon, riid As CLSID, ByVal fown As Long, lpUnk As Object) As Long
Public 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

Public Const SHGFI_ICON = &H100
Public Const SHGFI_LARGEICON = &H0
Public Const SHGFI_SMALLICON = &H1
Public Const S_OK = &H0

Public Function IconHandleToPicture(hIcon As Long) As IPictureDisp '把图标句柄转为IPictureDisp (IPictureDisp类似于StdPicture)
Dim cls_id As CLSID
Dim Ret As Long
Dim IconParameter As TypeIcon
Dim lpUnk As IUnknown

With IconParameter
.cbSize = Len(IconParameter)
.picType = vbPicTypeIcon
.hIcon = hIcon
End With

With cls_id
.id(8) = &HC0
.id(15) = &H46
End With

Ret = OleCreatePictureIndirect(IconParameter, cls_id, 1, lpUnk)
If Ret = S_OK Then Set IconHandleToPicture = lpUnk

End Function

'以下是获得文件图标句柄并调用IconHandleToPicture将图标句柄转为IPictureDisp
Public Function GetFileIcon(FilePath, Optional ByVal SmallIcon As Boolean = False) As IPictureDisp
Dim hIcon As Long
Dim sh_info As SHFILEINFO

If SmallIcon = True Then
SHGetFileInfo FilePath, 0, sh_info, Len(sh_info), SHGFI_ICON Or SHGFI_SMALLICON
Else
SHGetFileInfo FilePath, 0, sh_info, Len(sh_info), SHGFI_ICON Or SHGFI_LARGEICON
End If

hIcon = sh_info.hIcon
Set GetFileIcon = IconHandleToPicture(hIcon)

End Function

调用实例:
ListView.View = lvwReport
ListView.FullRowSelect = True
ListView.ColumnHeaders.Add , , "项目", 7000
ImageList.ListImages.Add , "记事本图标", GetFileIcon(Environ("WINDIR") & "\system32\notepad.exe", False)
ImageList.ListImages.Add , "计算器图标", GetFileIcon(Environ("WINDIR") & "\system32\calc.exe", False)
ListView.SmallIcons = ImageList '设置与ListView关联的ImageList控件。注意需要在ImageList控件中添加了图片以后才能将ImageList与ListView关联,否则会出错。
ListView.ListItems.Add , "显示记事本图标", "显示记事本图标", , "记事本图标"
ListView.ListItems.Add , "显示计算器图标", "显示计算器图标", , "计算器图标"
ListView.ListItems.Add , "无图标", "无图标"

回答2:

企业版自带 listview控件 部件---microsoft windows common controls 6.0

回答3:

common dialoge 控件,在工具箱空白处点击鼠标右键——————添加控件————common dialoge,找到这个就行了,vb自己带的,可以参考
http://www.360doc.com/content/09/0609/08/19147_3823176.shtml用法

回答4:

'添加ListView1
Private Type FileInfo
FileName As String
FileSize As String
FileType As String
FileDateLastModified As String
End Type
Private Function GetFileInfo(ByVal folder As String) As FileInfo()
Dim fso, fd, fd1, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set fd = fso.GetFolder(folder)
Dim i As Integer: i = 0
Dim fileInfoArr() As FileInfo
For Each fd1 In fd.SubFolders
ReDim Preserve fileInfoArr(i)
fileInfoArr(i).FileName = fd1.Name
fileInfoArr(i).FileType = fd1.Type
fileInfoArr(i).FileDateLastModified = fd1.DateLastModified
i = i + 1
Next
For Each f1 In fd.Files
ReDim Preserve fileInfoArr(i)
fileInfoArr(i).FileName = f1.Name
fileInfoArr(i).FileSize = f1.Size \ 1024 & "KB"
fileInfoArr(i).FileType = f1.Type
fileInfoArr(i).FileDateLastModified = f1.DateLastModified
i = i + 1
Next
GetFileInfo = fileInfoArr
End Function

Private Sub Form_Load()
ListView1.ColumnHeaders.Add , , "名称"
ListView1.ColumnHeaders.Add , , "大小"
ListView1.ColumnHeaders.Add , , "类型"
ListView1.ColumnHeaders.Add , , "修改时间"
ListView1.View = lvwReport
Dim fiArr() As FileInfo
fiArr = GetFileInfo("d:\")
For i = 0 To UBound(fiArr)
ListView1.ListItems.Add , , fiArr(i).FileName
ListView1.ListItems(i + 1).SubItems(1) = fiArr(i).FileSize
ListView1.ListItems(i + 1).SubItems(2) = fiArr(i).FileType
ListView1.ListItems(i + 1).SubItems(3) = fiArr(i).FileDateLastModified
Next
End Sub