Vb6 如何在Visual Basic 6中将文件夹图标附加到列表视图中的文件夹

Vb6 如何在Visual Basic 6中将文件夹图标附加到列表视图中的文件夹,vb6,Vb6,如何将文件夹图标附加到ListView文件夹?这就是我尝试过的: Do While sfolder name“” 对于i=0到dirList.ListCount-1 w=1 hIcon=ExtractAssociatedIcon(App.hInstance,“C:\Windows”,3) 如果sFolderName“”和sFolderName“”,则 如果(GetAttr(sPath&sFolderName)和vbDirectory)=vbDirectory,则 ListView2.ListI

如何将文件夹图标附加到ListView文件夹?这就是我尝试过的:

Do While sfolder name“”
对于i=0到dirList.ListCount-1
w=1
hIcon=ExtractAssociatedIcon(App.hInstance,“C:\Windows”,3)
如果sFolderName“”和sFolderName“”,则
如果(GetAttr(sPath&sFolderName)和vbDirectory)=vbDirectory,则
ListView2.ListItems.add,sFolderName,Picture2.Picture
Picture2.AutoRedraw=True
图2.Cls
DrawIcon Me.Picture2,0,0,hIcon
如果结束
'尝试了以下相同的结果
如果为空(hIcon),则
picBuff.Picture=Picture2.Picture
'图片
其他的
'设置picBuff.Picture=Picture2.Picture
'设置picBuff.Picture=无
”“是吗
'picBuff.Picture=Picture2.Picture
'DrawIcon picBuff.hdc,0,0,hIcon
”“是吗
如果结束
sFolderName=Dir
如果结束
...
环


(编辑:转换为易读文本,尽管它仅由图像和代码组成。Herb。)

您需要将图标添加到ImageList,将ImageList与ListView2关联,然后将Add方法中的Icon参数设置为将图标添加到ImageList时使用的键。嗨,Jac,谢谢你的回复,上面发布的代码有点乱,我已经将图标图像添加到ImageList中,但它没有显示图标,直到我在调用Imagelist中的图标时更改了一个数字,我诚挚的感谢Base64,只需在每个代码行的开头添加4个空格,您的代码就不再混乱。您需要将图标添加到Imagelist中,将Imagelist与ListView2关联,然后将Add方法中的Icon参数设置为将图标添加到ImageList时使用的键。嗨,Jac,谢谢你的回复,上面发布的代码有点乱,我已经将图标图像添加到ImageList中,但它没有显示图标,直到我在调用Imagelist中的图标时更改了一个数字,我诚挚的感谢Base64,只需在每个代码行的开头添加4个空格,您的代码就不再混乱。
Do While sFolderName <> ""
    For i = 0 To dirList.ListCount - 1  
    w = 1    
    hIcon = ExtractAssociatedIcon(App.hInstance, "C:\Windows", 3)
    If sFolderName <> "" And sFolderName <> "" Then
        If (GetAttr(sPath & sFolderName) And vbDirectory) = vbDirectory Then
            ListView2.ListItems.add , , sFolderName, Picture2.Picture
            Picture2.AutoRedraw = True
            Picture2.Cls
            DrawIcon Me.Picture2, 0, 0, hIcon
        End If

        'Tried the below same result
        If IsNull(hIcon) Then
            picBuff.Picture = Picture2.Picture
            'picDefault.Picture
        Else
            'Set picBuff.Picture = Picture2.Picture
            'Set picBuff.Picture = Nothing
            'DoEvents
            'picBuff.Picture = Picture2.Picture      
            'DrawIcon picBuff.hdc, 0, 0, hIcon
            'DoEvents
        End If
        sFolderName = Dir
    End If
    ...
Loop