您好,请教VB获取外部程序listview内容问题 5
您好,我以前用这个程序可以获得通达信炒股软件的持仓信息(一个listview表格),现在软件升级后只能获取正确的行列数,内容无法获取,两外在winxp下可以得到资源管理器...
您好,我以前用这个程序可以获得通达信炒股软件的持仓信息(一个listview表格),现在软件升级后只能获取正确的行列数,内容无法获取,两外在winxp下可以得到资源管理器的listview内容,到win7下也只能获取正确的行列数了,您能帮帮我吗?程序如下
Private Sub Command1_Click()
nMaxLen = 1023
ReDim szBuf(nMaxLen)
sum = 0
mhWnd = Val(InputBox("输入listview句柄:")) '69190 '用spy++获得的listview句柄
If mhWnd > 0 Then
Call GetWindowThreadProcessId(mhWnd, dwProcessId)
hProcess = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0&, dwProcessId)
If hProcess <> 0 Then
lpTextRemote = VirtualAllocEx(ByVal hProcess, ByVal 0&, nMaxLen + 1, MEM_COMMIT, PAGE_READWRITE)
lpListItemRemote = VirtualAllocEx(ByVal hProcess, ByVal 0&, Len(lvItemLocal), MEM_COMMIT, PAGE_READWRITE)
End If
lListItemCount = SendMessage(mhWnd, LVM_GETITEMCOUNT, 0&, ByVal 0&)
lSubItemCount = GetColumnHeaderCount(mhWnd) - 1
For k = 0 To lListItemCount - 1
lItemIndex = k
For j = 0 To lSubItemCount
lSubItemIndex = j
bWriteOK = WriteProcessMemory(ByVal hProcess, ByVal lpTextRemote, szBuf(0), nMaxLen + 1, dwBytesWrite)
lvItemLocal.iItem = lItemIndex
lvItemLocal.iSubItem = lSubItemIndex
lvItemLocal.mask = LVIF_TEXT
lvItemLocal.cchTextMax = nMaxLen
lvItemLocal.pszText = lpTextRemote
dwBytesWrite = 0
bWriteOK = WriteProcessMemory(ByVal hProcess, ByVal lpListItemRemote, ByVal VarPtr(lvItemLocal), Len(lvItemLocal), dwBytesWrite)
i = SendMessage(mhWnd, LVM_GETITEMTEXT, lItemIndex, ByVal lpListItemRemote)
bSuccess = ReadProcessMemory(ByVal hProcess, ByVal lpTextRemote, szBuf(0), nMaxLen + 1, dwBytesRead)
i = InStrB(szBuf, ChrB(0))
If i > 1 Then i = i - 1
sItemText = StrConv(LeftB(szBuf, i), vbUnicode)
sOutput = sOutput & sItemText & ","
Next
ReDim Preserve ss(0 To sum)
ss(k) = Left(sOutput, Len(sOutput) - 1)
sum = sum + 1
sOutput = ""
Next
If UBound(ss()) > 0 Then
For i = 0 To UBound(ss())
MsgBox ss(i) 'XP下取资源管理器的内容正常,但取不到通达信持仓列表的内容
Next
End If
End If
End Sub
Private Function GetColumnHeaderCount(ByVal hLVWnd As Long) As Long
Dim hHD As Long
hHD = SendMessage(hLVWnd, LVM_GETHEADER, 0, ByVal 0)
If hHD = 0 Then Exit Function
GetColumnHeaderCount = SendMessage(hHD, HDM_GETITEMCOUNT, 0, ByVal 0)
End Function 展开
Private Sub Command1_Click()
nMaxLen = 1023
ReDim szBuf(nMaxLen)
sum = 0
mhWnd = Val(InputBox("输入listview句柄:")) '69190 '用spy++获得的listview句柄
If mhWnd > 0 Then
Call GetWindowThreadProcessId(mhWnd, dwProcessId)
hProcess = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0&, dwProcessId)
If hProcess <> 0 Then
lpTextRemote = VirtualAllocEx(ByVal hProcess, ByVal 0&, nMaxLen + 1, MEM_COMMIT, PAGE_READWRITE)
lpListItemRemote = VirtualAllocEx(ByVal hProcess, ByVal 0&, Len(lvItemLocal), MEM_COMMIT, PAGE_READWRITE)
End If
lListItemCount = SendMessage(mhWnd, LVM_GETITEMCOUNT, 0&, ByVal 0&)
lSubItemCount = GetColumnHeaderCount(mhWnd) - 1
For k = 0 To lListItemCount - 1
lItemIndex = k
For j = 0 To lSubItemCount
lSubItemIndex = j
bWriteOK = WriteProcessMemory(ByVal hProcess, ByVal lpTextRemote, szBuf(0), nMaxLen + 1, dwBytesWrite)
lvItemLocal.iItem = lItemIndex
lvItemLocal.iSubItem = lSubItemIndex
lvItemLocal.mask = LVIF_TEXT
lvItemLocal.cchTextMax = nMaxLen
lvItemLocal.pszText = lpTextRemote
dwBytesWrite = 0
bWriteOK = WriteProcessMemory(ByVal hProcess, ByVal lpListItemRemote, ByVal VarPtr(lvItemLocal), Len(lvItemLocal), dwBytesWrite)
i = SendMessage(mhWnd, LVM_GETITEMTEXT, lItemIndex, ByVal lpListItemRemote)
bSuccess = ReadProcessMemory(ByVal hProcess, ByVal lpTextRemote, szBuf(0), nMaxLen + 1, dwBytesRead)
i = InStrB(szBuf, ChrB(0))
If i > 1 Then i = i - 1
sItemText = StrConv(LeftB(szBuf, i), vbUnicode)
sOutput = sOutput & sItemText & ","
Next
ReDim Preserve ss(0 To sum)
ss(k) = Left(sOutput, Len(sOutput) - 1)
sum = sum + 1
sOutput = ""
Next
If UBound(ss()) > 0 Then
For i = 0 To UBound(ss())
MsgBox ss(i) 'XP下取资源管理器的内容正常,但取不到通达信持仓列表的内容
Next
End If
End If
End Sub
Private Function GetColumnHeaderCount(ByVal hLVWnd As Long) As Long
Dim hHD As Long
hHD = SendMessage(hLVWnd, LVM_GETHEADER, 0, ByVal 0)
If hHD = 0 Then Exit Function
GetColumnHeaderCount = SendMessage(hHD, HDM_GETITEMCOUNT, 0, ByVal 0)
End Function 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询