' Returns an absolute pidl's path only (doesn't rtn display names!) Public Function GetPathFromPIDL(pidl As Long) As String Dim sPath As String * MAX_PATH ' 260 If (SUCCEEDED(SHGetPathFromIDList(pidl, sPath))) Then GetPathFromPIDL = GetStrFromBufferA(sPath) End If End FunctionPublic Function DoLVNotify(hwndForm As Long, lParam As Long) As Long .............. Case NM_CLICK Dim lSelItem As Long
' Get the selected listview item's index lSelItem = ListView_GetSelectedItem(hwndLV) If (lSelItem = -1) Then Exit Function
' Get the selected listview item's LVITEM struct lvi.mask = LVIF_PARAM lvi.iItem = lSelItem If (ListView_GetItem(hwndLV, lvi) = False) Then Exit Function
' Fill the item's ITEMDATA struct from it's pointer MoveMemory lvid, ByVal lvi.lParam, Len(lvid) Debug.Print "Path " & GetPathFromPIDL(lvid.pidlRel) ..................... End Function
To:bbe 请问lvid应该Dim为什么?
这部分代码还不是核心 只是处理TreeView的通知消息(相当于VB的事件)而已
Dim lvid As LVITEMDATA 你是要问这个吗?
Dim lvid As LVITEMDATA => Compile error: User-defined type not defined
' Contains pertinent info we'll use a lot for each inserted listview item. ' Each item's LVITEM lParam member will contain a pointer to this struct. Public Type LVITEMDATA isfParent As IShellFolder ' pointer to the parent item's shell folder interface pidlRel As Long ' item's pidl (relative to it's parent folder) ulAttribs As Long ' item's SHGAO_ attributes End Type有可能是类型库ISHF_EX.TLB的引用问题
Dim lvid As LVITEMDATA 现在可以了运行时,点ListView1的文件(夹)出错: vb6.exe - 应用程序错误 "0x082444f6"指令引用的"0x082444f6"内存。该内存不能为"read"
纯API建立TreeView、ListView并不困难难就难在它是使用 Shell接口 得到文件信息的
而VB对COM的支持封装得太好了,无法直接对某个接口进行操作
所以那个程序是自己写的接口声明,与标准的不同
再加上找不到这方面系统点的资料
Public Function GetPathFromPIDL(pidl As Long) As String
Dim sPath As String * MAX_PATH ' 260
If (SUCCEEDED(SHGetPathFromIDList(pidl, sPath))) Then
GetPathFromPIDL = GetStrFromBufferA(sPath)
End If
End FunctionPublic Function DoLVNotify(hwndForm As Long, lParam As Long) As Long
..............
Case NM_CLICK
Dim lSelItem As Long
' Get the selected listview item's index
lSelItem = ListView_GetSelectedItem(hwndLV)
If (lSelItem = -1) Then Exit Function
' Get the selected listview item's LVITEM struct
lvi.mask = LVIF_PARAM
lvi.iItem = lSelItem
If (ListView_GetItem(hwndLV, lvi) = False) Then Exit Function
' Fill the item's ITEMDATA struct from it's pointer
MoveMemory lvid, ByVal lvi.lParam, Len(lvid)
Debug.Print "Path " & GetPathFromPIDL(lvid.pidlRel)
.....................
End Function
请问lvid应该Dim为什么?
只是处理TreeView的通知消息(相当于VB的事件)而已
=>
Compile error:
User-defined type not defined
' Each item's LVITEM lParam member will contain a pointer to this struct.
Public Type LVITEMDATA
isfParent As IShellFolder ' pointer to the parent item's shell folder interface
pidlRel As Long ' item's pidl (relative to it's parent folder)
ulAttribs As Long ' item's SHGAO_ attributes
End Type有可能是类型库ISHF_EX.TLB的引用问题
vb6.exe - 应用程序错误
"0x082444f6"指令引用的"0x082444f6"内存。该内存不能为"read"
http://folderprotector.myrice.com/edeskvb2.rar
我把您给的代码放到edeskvb2就行了
(我开始是用VBExplorer测试的,不行)另:上面的连接下不了再次谢谢!