从SysListView32获取数据

时间:2016-11-06 20:03:27

标签: vba vb6

我正在尝试使用SysListView32LVM_GETITEMTEXT获取数据,但我只是得到一个空字符串。它给出了字符数,但没有显示实际文本。有人可以帮忙吗?代码如下

Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETITEMTEXT As Long = (LVM_FIRST + 45)

Private Type LV_ITEM
    mask         As Long
    iItem        As Long
    iSubItem     As Long
    state        As Long
    stateMask    As Long
    pszText      As String
    cchTextMax   As Long
    iImage       As Long
    lParam       As Long
    iIndent      As Long
End Type

Dim lvi As LV_ITEM
Dim r as long 

lvi.cchTextMax = MAX_PATH
lvi.pszText = Space$(MAX_PATH)

r = SendMessage(Handle, LVM_GETITEMTEXT, 0, lvi)

data = Left(lvi.pszText, r)

If Trim(data) <> "" Then MsgBox (data)

1 个答案:

答案 0 :(得分:0)

need to set the LVIF_TEXT flag声明pszText指向有效的缓冲区。

Private Const LVIF_TEXT As Long = &H1
lvi.mask = LVIF_TEXT
lvi.cchTextMax = MAX_PATH
lvi.pszText = Space$(MAX_PATH)