*****超难问题跪求高手帮忙,得到另外一个外部程序的VirtualTrees控件的句柄后,如何读出其中内容?******************* ( 积分:

  • 主题发起人 主题发起人 lijianzhou
  • 开始时间 开始时间
L

lijianzhou

Unregistered / Unconfirmed
GUEST, unregistred user!
*****超难问题跪求高手帮忙,得到另外一个外部程序的VirtualTrees控件的句柄后,如何读出其中内容?******************* ( 积分: 100 )<br />我想通过自己的程序发送消息去取得另外一个程序里的VirtualTrees列表里所有值或特定值,TVirtualTrees是第三方控件,类似TreeView,可以到盒子去下,万分感谢.

VirtualTrees数结构如下:


|□我的照片
|______□生活照片
|
|______________________□照片1
|______________________□照片2
 
这个办法未必好.
我看不如使用中间数据交换更好.
将VirtualTrees的值或特定值写入中间文件, 或数据库
另外一个程序直接到中间文件或数据库取数, 这样就没有难度了
 
由于工作需要原因,我写的程序需要读取VirtualTrees里的一个特定值,如&quot;照片2&quot;,判断是否有,如果有,是否被选中.
因为那个有VirtualTrees控件的程序不是本人写的,是另外一个公司开发的,

如果是treeview的话是没问题的,我已经写好,不过用在VirtualTrees上不行.

以下是取treeview值的方法:



function TreeNodeGetNext(mHandle: THandle; mTreeItem: HTreeItem): HTreeItem;
var
vParentID: HTreeItem;
begin
Result := nil;
if (mHandle &lt;&gt; 0) and (mTreeItem &lt;&gt; nil) then begin
Result := TreeView_GetChild(mHandle, mTreeItem);
if Result = nil then
Result := TreeView_GetNextSibling(mHandle, mTreeItem);
vParentID := mTreeItem;
while (Result = nil) and (vParentID &lt;&gt; nil) do begin
vParentID := TreeView_GetParent(mHandle, vParentID);
Result := TreeView_GetNextSibling(mHandle, vParentID);
end;
end;
end; { TreeNodeGetNext }

function TreeNodeGetLevel(mHandle: THandle; mTreeItem: HTreeItem): Integer;
var
vParentID: HTreeItem;
begin
Result := -1;
if (mHandle &lt;&gt; 0) and (mTreeItem &lt;&gt; nil) then begin
vParentID := mTreeItem;
repeat
Inc(Result);
vParentID := TreeView_GetParent(mHandle, vParentID);
until vParentID = nil;
end;
end; { TreeNodeGetLevel }

procedure GetTreeViewText(mHandle: THandle);
var
vItemCount: Integer;
vBuffer: array[0..255] of Char;
vProcessId: DWORD;
vProcess: THandle;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
I: Integer;
vItem: TTVItem;
vTreeItem: HTreeItem;
tmpstr:string;
h1:Hwnd;
begin
tmpstr:='';
GetWindowThreadProcessId(mHandle, @vProcessId);
vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, vProcessId);
vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,PAGE_READWRITE);
try
vItemCount := TreeView_GetCount(mHandle);
vTreeItem := TreeView_GetRoot(mHandle);
for I := 0 to vItemCount - 1 do begin
with vItem do begin
mask := TVIF_TEXT;
cchTextMax := SizeOf(vBuffer);
pszText := Pointer(Cardinal(vPointer) + SizeOf(vItem));
hItem := vTreeItem;
end;
WriteProcessMemory(vProcess, vPointer, @vItem,SizeOf(vItem), vNumberOfBytesRead);
SendMessage(mHandle, TVM_GETITEM, 0, lparam(vPointer));
ReadProcessMemory(vProcess, Pointer(Cardinal(vPointer) + SizeOf(TLVItem)), @vBuffer[0], SizeOf(vBuffer), vNumberOfBytesRead);
tmpStr:=lowercase(StringOfChar(#9, TreeNodeGetLevel(mHandle, vTreeItem)) + vBuffer);
showmessage(tmpstr);
if (pos('照片2',tmpstr)&gt;0) or (pos('照片1',tmpstr)&gt;0) then
begin
h1:=GetParent(mHandle);
end else
vTreeItem := TreeNodeGetNext(mHandle, vTreeItem);
end;
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
end;
end;

function GetTreeSelectText(const TreeHand: HWND): String;
var
hCurItem: HTREEITEM;
lNodeText: String;
ltvItem: TTVItem;
h: HWND;
C, i: integer;
Buff: PChar;
S: array[0..1024] of char;
PID: THandle;
PRC: THandle;
R: Cardinal;
begin
Result := '';
hCurItem := HTREEITEM(SendMessage( TreeHand, TVM_GETNEXTITEM, TVGN_CARET, 0 ));
if (hCurItem = nil) then Exit;
GetWindowThreadProcessId(TreeHand, @PID);
PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID);
Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
FillChar(ltvItem, SizeOf(ltvItem), 0);
with ltvItem do
begin
mask := TVIF_TEXT;
hItem := hCurItem;
cchTextMax := 2048;
pszText := PChar(integer(Buff) + SizeOf(ltvItem) * 4);
end;
WriteProcessMemory(PRC, Buff, @ltvItem, Sizeof(ltvItem), R);
SendMessage(TreeHand, TVM_GETITEM, 0, LongInt(Buff));
ReadProcessMemory(PRC, Buff, @ltvItem, Sizeof(ltvItem), R);
ReadProcessMemory(PRC, PChar(integer(Buff) + SizeOf(ltvItem) * 4), @S[0], SizeOf(S), R);
Result := Trim(S);
VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE);
CloseHandle(PRC);
end;
 
看来得进程DLL注入了?
 
&quot;看来得进程DLL注入了?&quot;


能具体点吗?
 
已经发送邮件给你.
 
接受答案了.
 
后退
顶部