K
killtimeer
Unregistered / Unconfirmed
GUEST, unregistred user!
function ListViewColumnCount(mHandle: THandle): Integer;
begin
Result := Header_GetItemCount(ListView_GetHeader(mHandle));
end; { ListViewColumnCount }
function GetLVText(mHandle: THandle): Boolean;
var
vColumnCount: Integer;
vItemCount: Integer;
I, J: Integer;
vBuffer: array[0..255] of Char;
vProcessId: DWORD;
vProcess: THandle;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
S: string;
vItem: TLVItem;
begin
result := False;
vColumnCount := ListViewColumnCount(mHandle);
if vColumnCount <= 0 then 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, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
try
for I := 0 to vItemCount - 1 do begin
S := '';
for J := 0 to vColumnCount - 1 do begin
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 + #9 + vBuffer;
end;
Delete(S, 1, 1);
showmessage(S);
end;
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
end;
result := True;
end; { GetListViewText }
调用 GetLVText(Handle) 可以看到外部程序的 ListView 项目的内容!!!
但有一个软件(万象网管2004服务端) 的 ListView 项目的内容用上面的代码无法正确取出!!!! (万象网管2004服务端 也是用 DELPHI 做的)
请大家帮调试一下, 问题出在什么地方, 先多谢大家了.......
begin
Result := Header_GetItemCount(ListView_GetHeader(mHandle));
end; { ListViewColumnCount }
function GetLVText(mHandle: THandle): Boolean;
var
vColumnCount: Integer;
vItemCount: Integer;
I, J: Integer;
vBuffer: array[0..255] of Char;
vProcessId: DWORD;
vProcess: THandle;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
S: string;
vItem: TLVItem;
begin
result := False;
vColumnCount := ListViewColumnCount(mHandle);
if vColumnCount <= 0 then 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, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
try
for I := 0 to vItemCount - 1 do begin
S := '';
for J := 0 to vColumnCount - 1 do begin
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 + #9 + vBuffer;
end;
Delete(S, 1, 1);
showmessage(S);
end;
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
end;
result := True;
end; { GetListViewText }
调用 GetLVText(Handle) 可以看到外部程序的 ListView 项目的内容!!!
但有一个软件(万象网管2004服务端) 的 ListView 项目的内容用上面的代码无法正确取出!!!! (万象网管2004服务端 也是用 DELPHI 做的)
请大家帮调试一下, 问题出在什么地方, 先多谢大家了.......