将SysListView32从外部应用程序获取到Excel(64位系统)

时间:2018-12-14 12:21:42

标签: vba syslistview32

在64位系统上,(存在一个已知的SysListView32句柄)。我想将此列表的元素带到Excel工作表中,但从未发生过。我手里有以下代码,但没有得到必要的值。我在互联网上找到并尝试了许多不同的代码,但都没有成功。 在各种论坛上发表的评论中都写道:SysListView32元素不是64位,而是真实的,而是虚拟的,并且无法读取列表(据我所知)。如果可以的话,我将不胜感激。 非常感谢

Option Explicit
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal Hwnd As LongPtr, ByVal wMsg As LongPtr, ByVal wParam As LongPtr, lParam As Any) As Long

Private Const LVM_FIRST = &H1000
Private Const LVM_GETITEMCOUNT = (LVM_FIRST + 4)
Private Const LVM_GETITEM = (LVM_FIRST + 5)
Public Const LVM_GETITEMTEXT As Long = (LVM_FIRST + 20)

Private Sub Command1_Click()
    Dim A, result      As Long
    Dim b           As Long
    Dim Hwnd    As Long
    Dim lvi     As LVITEM
    Hwnd = 395682 'SysListView32 handle'i
    b = SendMessage(Hwnd, LVM_GETITEMCOUNT, 0, 0)
    b = b - 1
    For A = 0 To b - 1
        lvi.mask = LVIF_TEXT
        lvi.iItem = A
        ListView_GetItem Hwnd, lvi
        Cells(A + 1, 1) = lvi.pszText
        Cells(A + 1, 2) = SendMessage(Hwnd, LVM_GETITEMTEXT, A, lvi)
        Cells(A + 1, 3) = LVM_GETITEMTEXT
    Next
End Sub

Results:
b=90 (SysListView32 item counting is working)
All of Column 2 cells = 0 '<= my goal, but no zero
All of Column 3 cells = 4116 'what is this

0 个答案:

没有答案