Home > Back-end >  Delphi how to call the sendmessage access to take other program window listviewj data in a content
Delphi how to call the sendmessage access to take other program window listviewj data in a content

Time:09-20

This is my code, online version of the c + + written, but not know where the wrong is
But cannot read data, which a great god help me to study the
Procedure TForm1. Btn1Click (Sender: TObject);
Var
WHWND hlistview: HWND;
Headerhwnd: Integer;
Rows, cols: Integer;
ThreadID: DWORD;
ProcessID: DWORD;
HProcess: THandle;
P_lvitem: ^ TLVItem;
Tmplvitem: TLVItem;
I, j: Integer;
PItem: LPTSTR;
PTR: DWORD;
ItemBuf: an array of Char [0.. 511];
OutSize WriteSize: dwords.
S: a string;
The begin
WHWND:=FindWindow (' # 32770 ', 'Windows task manager).
WHWND:=FindWindowEx (WHWND, 0, '# 32770, nil);
Hlistview:=FindWindowEx (WHWND, 0, 'SysListView32, nil);
//ShowMessage (IntToStr (hlistview));

//total number: the number of process
Rows:=SendMessage (hListview LVM_GETITEMCOUNT, 0, 0).
//list the number of columns
Headerhwnd:=SendMessage (hListview LVM_GETHEADER, 0, 0).//listview column head handle
Cols:=SendMessage (headerhwnd HDM_GETITEMCOUNT, 0, 0).

ThreadID:=GetWindowThreadProcessId (hListview, @ ProcessID);
//open and insert process
HProcess:=OpenProcess (PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE or PROCESS_QUERY_INFORMATION, FALSE, ProcessID);
//application code memory area
P_lvitem:=VirtualAllocEx (hProcess, nil, SizeOf (TLVITEM), MEM_COMMIT, PAGE_READWRITE);
GetMem (p_lvitem, SizeOf (TLVITEM));

For I:=0 to do rows - 1
The begin
For j:=0 to do cols - 1
The begin
Tmplvitem. Mask:=LVIF_TEXT;
Tmplvitem. IItem:=I;
Tmplvitem. ISubItem:=j;
Tmplvitem. CchTextMax:=512;

PItem:=nil;
PItem:=LPSTR (VirtualAllocEx (hProcess, nil, 512, MEM_COMMIT, PAGE_READWRITE));
Tmplvitem. PszText:=pItem;


WriteProcessMemory (hProcess, p_lvitem, @ tmplvitem, sizeof (tmplvitem), WriteSize);
SendMessage (hListview LVM_GETITEMW, I, an Integer (p_lvitem));
ZeroMemory (@ ItemBuf, 512);
ReadProcessMemory (hProcess, pItem. @ ItemBuf, 512, OutSize);
S:=s + '+ ItemBuf;
VirtualFreeEx (hProcess, pItem, 0, MEM_RELEASE);
end;
Mmo1. Lines. The Add (s);
end;

VirtualFreeEx (hProcess, p_lvitem, 0, MEM_RELEASE)
The CloseHandle (hProcess);/open/close the process object

end;

CodePudding user response:

You posted at least a complete code, compile all, however,

CodePudding user response:

A few days before debugging success under Windows 7 64

CodePudding user response:

The success of the upstairs? Can you grant instruction

CodePudding user response:

This is my current program code, can use the

The function ListViewColumnCount (mHandle: THandle) : Integer;
The begin
Result:=Header_GetItemCount (ListView_GetHeader (mHandle));

end; {ListViewColumnCount}

The function GetListViewText (mHandle: THandle; MStrings: TStrings) : Boolean;
Var
VColumnCount: Integer;
VItemCount: Integer;
I, J: Integer;
VBuffer: an array of Char [0.. 255];
VProcessId: DWORD;
VProcess: THandle;
VPointer: Pointer;
VNumberOfBytesRead: Cardinal;
S: a string;
VItem: TLVItem;
The begin
Result:=False;
If not Assigned (mStrings) then the Exit;
VColumnCount:=ListViewColumnCount (mHandle);
If vColumnCount & lt;=0 then the Exit;
VItemCount:=ListView_GetItemCount (mHandle);
GetWindowThreadProcessId (mHandle, @ vProcessId);
VProcess:=OpenProcess (PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, vProcessId);
VPointer:=VirtualAllocEx (vProcess, nil, 4096, the MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
MStrings. BeginUpdate;
Try
MStrings. The Clear;
For I:=0 to do begin vItemCount - 1
S:=';
For J:=0 to do begin vColumnCount - 1
With vItem do begin
Mask:=LVIF_TEXT;
IItem:=I;
ISubItem:=J;
CchTextMax:=SizeOf (vBuffer);
PszText:=Pointer (Cardinal (vPointer) + SizeOf (TLVItem));
end;
WriteProcessMemory (vProcess vPointer, @ vItem,
SizeOf (TLVItem), vNumberOfBytesRead);
SendMessage (mHandle LVM_GETITEM, I, lparam (vPointer));
ReadProcessMemory (vProcess, Pointer (Cardinal (vPointer) + SizeOf (TLVItem)),
@ vBuffer [0], SizeOf (vBuffer), vNumberOfBytesRead);
S:=S + ', '+ vBuffer;
end;
Delete (S, 1, 1);
MStrings. Add (S);
end;
The finally
VirtualFreeEx (vProcess vPointer, 0, MEM_RELEASE);
The CloseHandle (vProcess);
MStrings. EndUpdate;
end;
Result:=True;
end; {GetListViewText}

Add this sentence//button, so you'll have the contents of a listview in the memo
GetListViewText (listview handle, MemoText. Lines);

CodePudding user response:

By the way, the above code to reference CommCtrl

CodePudding user response:

Thank you very much, is just what I need
  • Related