首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

100分,怎么获取其它程序的TeitreeView控件里面的内容

2012-01-18 
100分在线求救,如何获取其它程序的TeitreeView控件里面的内容100分在线求救,如何获取其它程序的TeitreeVie

100分在线求救,如何获取其它程序的TeitreeView控件里面的内容
100分在线求救,如何获取其它程序的TeitreeView控件里面的内容。
本人主要想读取其它TeitreeView的内容,但是从来没有用过此控件网上根本找不到相关的信息
能获取到此控件的句柄,但是不知道如何发消息获取第一个节点的句柄(而且此控件好象和treeview控件不一样)我用   SendMessage(TeitreeView控件句柄,   TVM_GETNEXTITEM,   TVGN_ROOT,   ByVal   0)取不到节点的句柄。
哪位高手能帮我一下   谢谢了

注:主要是获取某个软件TeitreeView控件上的数据

[解决办法]
Option Explicit

Private Const MEM_RELEASE = &H8000

Private Const LVM_FIRST = &H1000
Private Const LVM_GETHEADER = LVM_FIRST + 31
Private Const LVM_GETITEMCOUNT = (LVM_FIRST + 4)

Private Const LVM_GETITEM = (LVM_FIRST + 5)
Private Const LVM_GETSTRINGWIDTH = (LVM_FIRST + 17)
Private Const LVM_GETCOLUMN = (LVM_FIRST + 25)
Private Const LVM_GETITEMTEXT = (LVM_FIRST + 45)
Private Const HDM_FIRST = &H1200
Private Const HDM_GETITEMCOUNT = (HDM_FIRST + 0)
Private Const HDM_ORDERTOINDEX = (HDM_FIRST + 15)

Private Const PROCESS_QUERY_INFORMATION = 1024
Private Const PROCESS_VM_OPERATION = &H8
Private Const PROCESS_VM_READ = &H10
Private Const PROCESS_VM_WRITE = &H20
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const MAX_LVMSTRING As Long = 255
Private Const MEM_COMMIT = &H1000
Private Const PAGE_READWRITE = &H4
Private Const LVIF_TEXT As Long = &H1

Private Const LVM_GETCOLUMNCOUNT = &HF11B

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

Private Declare Function OpenProcess Lib "kernel32 " (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32 " (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32 " (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32 " (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32 " (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long

Private Declare Function SendMessage Lib "user32 " Alias "SendMessageA " (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long

Private Declare Function CloseHandle Lib "kernel32 " (ByVal hObject As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32 " () As Long

Private Function GetListViewTextArray(ByVal hWindow As Long, ByVal ProcessID As Long) As String()
Dim result As Long
Dim myItem() As LV_ITEMA
Dim pHandle As Long
Dim pStrBufferMemory As Long
Dim pMyItemMemory As Long
Dim strBuffer() As Byte
Dim index As Long
Dim tmpString As String
Dim strLength As Long
Dim i As Integer, sum As Integer, j As Integer, hCount As Long
Dim strArr() As String, itemString As String
hCount = SendMessage(hWindow, LVM_GETHEADER, 0, 0)
If hCount > 0 Then


hCount = SendMessage(hCount, HDM_GETITEMCOUNT, 0, 0)
Else
hCount = 0
End If
ReDim strBuffer(MAX_LVMSTRING)
pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, ProcessID)
ReDim myItem(hCount)
For j = 0 To SendMessage(hWindow, LVM_GETITEMCOUNT, 0, 0) - 1
For i = 0 To hCount
pStrBufferMemory = VirtualAllocEx(pHandle, 0, MAX_LVMSTRING, MEM_COMMIT, PAGE_READWRITE)
myItem(i).mask = LVIF_TEXT
myItem(i).iSubItem = i
myItem(i).pszText = pStrBufferMemory
myItem(i).cchTextMax = MAX_LVMSTRING
pMyItemMemory = VirtualAllocEx(pHandle, 0, Len(myItem(i)), MEM_COMMIT, PAGE_READWRITE)
result = WriteProcessMemory(pHandle, pMyItemMemory, myItem(i), Len(myItem(i)), 0)
result = SendMessage(hWindow, LVM_GETITEMTEXT, j, ByVal pMyItemMemory)
If result = 0 Then
result = VirtualFreeEx(pHandle, pStrBufferMemory, 0, MEM_RELEASE)
result = VirtualFreeEx(pHandle, pMyItemMemory, 0, MEM_RELEASE)
Exit For
End If
result = ReadProcessMemory(pHandle, pStrBufferMemory, strBuffer(0), MAX_LVMSTRING, 0)
result = ReadProcessMemory(pHandle, pMyItemMemory, myItem(i), Len(myItem(i)), 0)
tmpString = StrConv(strBuffer, vbUnicode)
tmpString = Left(tmpString, InStr(tmpString, vbNullChar) - 1)
itemString = itemString & tmpString & ", "
result = VirtualFreeEx(pHandle, pStrBufferMemory, 0, MEM_RELEASE)
result = VirtualFreeEx(pHandle, pMyItemMemory, 0, MEM_RELEASE)
Next
ReDim Preserve strArr(0 To sum)
strArr(j) = Left(itemString, Len(itemString) - 1)
sum = sum + 1
itemString = " "
Next
result = CloseHandle(pHandle)
GetListViewTextArray = strArr
End Function
[解决办法]
那个软件我看了,试了一下。拦截不到任何有用的消息。唯一的收获是证实了这个软件中的TeitreeView控件和treeView控件根本不搭边

这样吧,这个软件不是可以备份数据吗,你把备份的数据放到服务器上,然后,其他人从服务器上获取数据后,再导入数据吧

或者,让老板花钱,每台机器都购买一套

热点排行