Get the text of ListView in other processes

zhaozj2021-02-16  46

(* //

Title: Get the text of ListView in other processes

Description: WINDOW2000 Delphi6 debugging

Design: zswang

Support: wjhu111@21cn.com

Date: 2004-03-25

// *)

Uses commctrl;

Function ListviewColumncount (Mhandle: Thandle): Integer;

Begin

Result: = header_getitemcount (ListView_getheader (MHANDLE));

End; {listviewcolumncount}

Function getListViewText (Mhaldle: Thandle; Mstrings: Tstrings): boolean;

VAR

Vcolumncount: integer;

Vitemcount: Integer;

I, J: Integer;

vbuffer: array [0..255] of char;

VProcessID: DWORD;

..

Vpointer: Pointer;

VNUMBEROFBYTESREAD: Cardinal

String;

VITEM: TLVITEM;

Begin

Result: = FALSE;

IF NOT ASSIGNED (MSTRINGS).

Vcolumncount: = listviewcolumncount (mhandle);

IF vcolumncount <= 0 dam

vitemcount: = listview_getitemcount (mhandle);

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;

For i: = 0 to vitemcount - 1 do begin

S: = '';

For j: = 0 to vcolumncount - 1 do begin

With Vitem do Begin

Mask: = LVIF_Text;

IIITEM: = I;

ISUBITEM: = J;

Cchtextmax: = sizeof (vbuffer);

PszText: = POINTER (VPointer) SizeOf (TLVItem));

END;

WriteProcessMemory (vprocess, vpointer, @VITEM,

SizeOf (TLVItem), vNumberofbytesRead;

SendMessage (Mhaldle, LVM_GetItem, I, LPARAM (VpoInter));

ReadProcessMemory (VProcess, Pointer (Cardinal (Vpointer) SIZEOF (TLVItem),

@vbuffer [0], sizeof (vbuffer), vNumberofbytesread;

S: = s # 9 vbuffer;

END;

Delete (s, 1, 1);

MStrings.Add (s);

Finally

VirtualFreeex (vProcess, Vpointer, 0, MEM_RELEASE);

CloseHandle (vProcess);

Mstrings.endupdate;

END;

RESULT: = TRUE;

End; {getListViewText}

// 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:

GetListViewText (

WindowFromPoint (Point (mouse.cursorpos.x, mouse.cursorpos.y),

Memotext.Lines);

END;

END;

转载请注明原文地址:https://www.9cbs.com/read-27898.html

New Post(0)