(* //
Title: Get the text of TreeView in other processes
Description: WINDOW2000 Delphi6 debugging
Design: zswang
Support: wjhu111@21cn.com
Date: 2004-03-26
// *)
Function TreenodegetNext (Mhandle: Thandle; MtreeItem: htreeItem): htreeItem
VAR
vparentid: htreeItem;
Begin
Result: = NIL;
IF (Mhandle <> 0) and (MtreeItem <> nil) THEN BEGIN
Result: = TreeView_Getchild (Mhaldle, MtreeItem);
if Result = nil dam
Result: = TreeView_getnextsibling (Mhaldle, MtreeItem);
vParentID: = MtreeItem;
While (result = nil) and (vParentID <> nil) do begin
vparentID: = TreeView_getparent (Mhaldle, vparentID);
Result: = TreeView_getnextsibling (Mhaldle, VParentID);
END;
END;
End; {TreenodegetNext}
Function Treenodegetlevel (Mhandle: Thandle; MtreeItem: htreeItem): Integer;
VAR
vparentid: htreeItem;
Begin
RESULT: = -1;
IF (Mhandle <> 0) and (MtreeItem <> nil) THEN BEGIN
vParentID: = MtreeItem;
Repeat
Inc (Result);
vparentID: = TreeView_getparent (Mhaldle, vparentID);
Until vParentId = NIL;
END;
End; {treenodegenetlevel}
Function GettreeViewText (Mhaldle: Thandle; Mstrings: tstrings): Boolean;
VAR
Vitemcount: Integer;
vbuffer: array [0..255] of char;
VProcessID: DWORD;
..
Vpointer: Pointer;
VNUMBEROFBYTESREAD: Cardinal
I: integer;
Vitem: ttvitem;
VtreeItem: htreeitym;
Begin
Result: = FALSE;
IF NOT ASSIGNED (MSTRINGS).
GetWindowThreadProcessId (Mhaldle, @vprocessid);
vprocess: = openprocess (Process_VM_Operation or Process_vm_read OR
Process_vm_write, false, vprocessid;
Vpointer: = VirtualaLoceX (vProcess, NIL, 4096, MEM_RESERVE or MEM_COMMIT,
Page_readwrite;
Mstrings.beginupdate;
Try
Mstrings.clear;
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) SizeOf (VITEM));
HITEM: = VTREEITEM;
END;
WriteProcessMemory (vprocess, vpointer, @VITEM,
SizeOf (Vitem), vNumberofbytesRead;
SendMessage (Mhaldle, TVM_GetItem, 0, LPARAM (VpoInter));
ReadProcessMemory (VProcess, Pointer (Cardinal (Vpointer) SIZEOF (TLVItem),
@vbuffer [0], sizeof (vbuffer), vNumberofbytesread;
Mstrings.add (StringOfchar (# 9, TreenodegegetLevel (Mhandle, VtreeItem)) vbuffer;
VtreeItem: = TreenodegetNext (Mhaldle, VtreeItem);
END;
Finally
VirtualFreeex (vProcess, Vpointer, 0, MEM_RELEASE);
CloseHandle (vProcess);
Mstrings.endupdate;
END;
RESULT: = TRUE;
End; {gettreeViewText}
// esample
Procedure TFORM1.FormCreate (Sender: TOBJECT);
Begin
RegisterhotKey (Handle, 1, MOD_WIN, VK_F2);
END;
Procedure TFORM1.FORMDESTROY (Sender: TOBJECT);
Begin
UnregisterhotKey (Handle, 1);
END;
Procedure TFORM1.WMHOTKEY (VAR MSG: TWMHOTKEY);
Begin
Case msg.hotKey of
1:
GetTreeViewText
WindowFromPoint (Point (mouse.cursorpos.x, mouse.cursorpos.y),
Memotext.Lines);
END;
END;